blob: 5e0198926744de6304ef913145038da0bd289e9b [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Lang86846e22014-06-03 15:48:54 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// loadimage.cpp: Defines image loading functions.
8
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/renderer/loadimage.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000010
11namespace rx
12{
13
Geoff Lang86846e22014-06-03 15:48:54 -040014void LoadA8ToRGBA8(size_t width, size_t height, size_t depth,
15 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
16 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017{
Geoff Lang86846e22014-06-03 15:48:54 -040018 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000019 {
Geoff Lang86846e22014-06-03 15:48:54 -040020 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000021 {
Geoff Lang86846e22014-06-03 15:48:54 -040022 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
23 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
24 for (size_t x = 0; x < width; x++)
25 {
26 dest[x] = static_cast<uint32_t>(source[x]) << 24;
27 }
28 }
29 }
30}
31
32void LoadA8ToBGRA8(size_t width, size_t height, size_t depth,
33 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
34 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
35{
36 // Same as loading to RGBA
37 LoadA8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch);
38}
39
40void LoadA32FToRGBA32F(size_t width, size_t height, size_t depth,
41 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
42 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
43{
44 for (size_t z = 0; z < depth; z++)
45 {
46 for (size_t y = 0; y < height; y++)
47 {
48 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
49 float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
50 for (size_t x = 0; x < width; x++)
51 {
52 dest[4 * x + 0] = 0.0f;
53 dest[4 * x + 1] = 0.0f;
54 dest[4 * x + 2] = 0.0f;
55 dest[4 * x + 3] = source[x];
56 }
57 }
58 }
59}
60
61void LoadA16FToRGBA16F(size_t width, size_t height, size_t depth,
62 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
63 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
64{
65 for (size_t z = 0; z < depth; z++)
66 {
67 for (size_t y = 0; y < height; y++)
68 {
69 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
70 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
71 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000072 {
73 dest[4 * x + 0] = 0;
74 dest[4 * x + 1] = 0;
75 dest[4 * x + 2] = 0;
76 dest[4 * x + 3] = source[x];
77 }
78 }
79 }
80}
81
Geoff Lang86846e22014-06-03 15:48:54 -040082void LoadL8ToRGBA8(size_t width, size_t height, size_t depth,
83 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
84 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000085{
Geoff Lang86846e22014-06-03 15:48:54 -040086 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000087 {
Geoff Lang86846e22014-06-03 15:48:54 -040088 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000089 {
Geoff Lang86846e22014-06-03 15:48:54 -040090 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
91 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
92 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000093 {
94 dest[4 * x + 0] = source[x];
95 dest[4 * x + 1] = source[x];
96 dest[4 * x + 2] = source[x];
97 dest[4 * x + 3] = 0xFF;
98 }
99 }
100 }
101}
102
Geoff Lang86846e22014-06-03 15:48:54 -0400103void LoadL8ToBGRA8(size_t width, size_t height, size_t depth,
104 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
105 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000106{
Geoff Lang86846e22014-06-03 15:48:54 -0400107 // Same as loading to RGBA
108 LoadL8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch);
109}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000110
Geoff Lang86846e22014-06-03 15:48:54 -0400111void LoadL32FToRGBA32F(size_t width, size_t height, size_t depth,
112 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
113 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
114{
115 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000116 {
Geoff Lang86846e22014-06-03 15:48:54 -0400117 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000118 {
Geoff Lang86846e22014-06-03 15:48:54 -0400119 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
120 float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
121 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000122 {
123 dest[4 * x + 0] = source[x];
124 dest[4 * x + 1] = source[x];
125 dest[4 * x + 2] = source[x];
126 dest[4 * x + 3] = 1.0f;
127 }
128 }
129 }
130}
131
Geoff Lang86846e22014-06-03 15:48:54 -0400132void LoadL16FToRGBA16F(size_t width, size_t height, size_t depth,
133 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
134 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000135{
Geoff Lang86846e22014-06-03 15:48:54 -0400136 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000137 {
Geoff Lang86846e22014-06-03 15:48:54 -0400138 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000139 {
Geoff Lang86846e22014-06-03 15:48:54 -0400140 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
141 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
142 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000143 {
144 dest[4 * x + 0] = source[x];
145 dest[4 * x + 1] = source[x];
146 dest[4 * x + 2] = source[x];
Geoff Langb69d39b2014-05-06 11:49:22 -0400147 dest[4 * x + 3] = gl::Float16One;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000148 }
149 }
150 }
151}
152
Geoff Lang86846e22014-06-03 15:48:54 -0400153void LoadLA8ToRGBA8(size_t width, size_t height, size_t depth,
154 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
155 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000156{
Geoff Lang86846e22014-06-03 15:48:54 -0400157 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000158 {
Geoff Lang86846e22014-06-03 15:48:54 -0400159 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000160 {
Geoff Lang86846e22014-06-03 15:48:54 -0400161 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
162 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
163 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000164 {
Geoff Lang86846e22014-06-03 15:48:54 -0400165 dest[4 * x + 0] = source[2 * x + 0];
166 dest[4 * x + 1] = source[2 * x + 0];
167 dest[4 * x + 2] = source[2 * x + 0];
168 dest[4 * x + 3] = source[2 * x + 1];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000169 }
170 }
171 }
172}
173
Geoff Lang86846e22014-06-03 15:48:54 -0400174void LoadLA8ToBGRA8(size_t width, size_t height, size_t depth,
175 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
176 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000177{
Geoff Lang86846e22014-06-03 15:48:54 -0400178 // Same as loading to RGBA
179 LoadLA8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch);
180}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000181
Geoff Lang86846e22014-06-03 15:48:54 -0400182void LoadLA32FToRGBA32F(size_t width, size_t height, size_t depth,
183 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
184 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
185{
186 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000187 {
Geoff Lang86846e22014-06-03 15:48:54 -0400188 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000189 {
Geoff Lang86846e22014-06-03 15:48:54 -0400190 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
191 float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
192 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000193 {
Geoff Lang86846e22014-06-03 15:48:54 -0400194 dest[4 * x + 0] = source[2 * x + 0];
195 dest[4 * x + 1] = source[2 * x + 0];
196 dest[4 * x + 2] = source[2 * x + 0];
197 dest[4 * x + 3] = source[2 * x + 1];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000198 }
199 }
200 }
201}
202
Geoff Lang86846e22014-06-03 15:48:54 -0400203void LoadLA16FToRGBA16F(size_t width, size_t height, size_t depth,
204 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
205 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000206{
Geoff Lang86846e22014-06-03 15:48:54 -0400207 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000208 {
Geoff Lang86846e22014-06-03 15:48:54 -0400209 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000210 {
Geoff Lang86846e22014-06-03 15:48:54 -0400211 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
212 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
213 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000214 {
Geoff Lang86846e22014-06-03 15:48:54 -0400215 dest[4 * x + 0] = source[2 * x + 0];
216 dest[4 * x + 1] = source[2 * x + 0];
217 dest[4 * x + 2] = source[2 * x + 0];
218 dest[4 * x + 3] = source[2 * x + 1];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000219 }
220 }
221 }
222}
223
Geoff Lang86846e22014-06-03 15:48:54 -0400224void LoadRGB8ToBGRX8(size_t width, size_t height, size_t depth,
225 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
226 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000227{
Geoff Lang86846e22014-06-03 15:48:54 -0400228 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000229 {
Geoff Lang86846e22014-06-03 15:48:54 -0400230 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000231 {
Geoff Lang86846e22014-06-03 15:48:54 -0400232 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
233 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
234 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000235 {
236 dest[4 * x + 0] = source[x * 3 + 2];
237 dest[4 * x + 1] = source[x * 3 + 1];
238 dest[4 * x + 2] = source[x * 3 + 0];
239 dest[4 * x + 3] = 0xFF;
240 }
241 }
242 }
243}
244
Geoff Lang86846e22014-06-03 15:48:54 -0400245void LoadRG8ToBGRX8(size_t width, size_t height, size_t depth,
246 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
247 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang632192d2013-10-04 13:40:46 -0400248{
Geoff Lang86846e22014-06-03 15:48:54 -0400249 for (size_t z = 0; z < depth; z++)
Geoff Lang632192d2013-10-04 13:40:46 -0400250 {
Geoff Lang86846e22014-06-03 15:48:54 -0400251 for (size_t y = 0; y < height; y++)
Geoff Lang632192d2013-10-04 13:40:46 -0400252 {
Geoff Lang86846e22014-06-03 15:48:54 -0400253 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
254 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
255 for (size_t x = 0; x < width; x++)
Geoff Lang632192d2013-10-04 13:40:46 -0400256 {
257 dest[4 * x + 0] = 0x00;
258 dest[4 * x + 1] = source[x * 2 + 1];
259 dest[4 * x + 2] = source[x * 2 + 0];
260 dest[4 * x + 3] = 0xFF;
261 }
262 }
263 }
264}
265
Geoff Lang86846e22014-06-03 15:48:54 -0400266void LoadR8ToBGRX8(size_t width, size_t height, size_t depth,
267 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
268 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang632192d2013-10-04 13:40:46 -0400269{
Geoff Lang86846e22014-06-03 15:48:54 -0400270 for (size_t z = 0; z < depth; z++)
Geoff Lang632192d2013-10-04 13:40:46 -0400271 {
Geoff Lang86846e22014-06-03 15:48:54 -0400272 for (size_t y = 0; y < height; y++)
Geoff Lang632192d2013-10-04 13:40:46 -0400273 {
Geoff Lang86846e22014-06-03 15:48:54 -0400274 const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch);
275 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
276 for (size_t x = 0; x < width; x++)
Geoff Lang632192d2013-10-04 13:40:46 -0400277 {
278 dest[4 * x + 0] = 0x00;
279 dest[4 * x + 1] = 0x00;
280 dest[4 * x + 2] = source[x];
281 dest[4 * x + 3] = 0xFF;
282 }
283 }
284 }
285}
286
Geoff Lang86846e22014-06-03 15:48:54 -0400287void LoadR5G6B5ToBGRA8(size_t width, size_t height, size_t depth,
288 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
289 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000290{
Geoff Lang86846e22014-06-03 15:48:54 -0400291 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000292 {
Geoff Lang86846e22014-06-03 15:48:54 -0400293 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000294 {
Geoff Lang86846e22014-06-03 15:48:54 -0400295 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
296 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
297 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000298 {
Geoff Lang86846e22014-06-03 15:48:54 -0400299 uint16_t rgb = source[x];
300 dest[4 * x + 0] = ((rgb & 0x001F) << 3) | ((rgb & 0x001F) >> 2);
301 dest[4 * x + 1] = ((rgb & 0x07E0) >> 3) | ((rgb & 0x07E0) >> 9);
302 dest[4 * x + 2] = ((rgb & 0xF800) >> 8) | ((rgb & 0xF800) >> 13);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000303 dest[4 * x + 3] = 0xFF;
304 }
305 }
306 }
307}
308
Geoff Lang86846e22014-06-03 15:48:54 -0400309void LoadR5G6B5ToRGBA8(size_t width, size_t height, size_t depth,
310 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
311 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000312{
Geoff Lang86846e22014-06-03 15:48:54 -0400313 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000314 {
Geoff Lang86846e22014-06-03 15:48:54 -0400315 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000316 {
Geoff Lang86846e22014-06-03 15:48:54 -0400317 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
318 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
319 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org36d0be92013-05-30 00:15:59 +0000320 {
Geoff Lang86846e22014-06-03 15:48:54 -0400321 uint16_t rgb = source[x];
322 dest[4 * x + 0] = ((rgb & 0xF800) >> 8) | ((rgb & 0xF800) >> 13);
323 dest[4 * x + 1] = ((rgb & 0x07E0) >> 3) | ((rgb & 0x07E0) >> 9);
324 dest[4 * x + 2] = ((rgb & 0x001F) << 3) | ((rgb & 0x001F) >> 2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000325 dest[4 * x + 3] = 0xFF;
326 }
327 }
328 }
329}
330
Geoff Lang86846e22014-06-03 15:48:54 -0400331void LoadRGBA8ToBGRA8(size_t width, size_t height, size_t depth,
332 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
333 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000334{
Geoff Lang86846e22014-06-03 15:48:54 -0400335 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000336 {
Geoff Lang86846e22014-06-03 15:48:54 -0400337 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000338 {
Geoff Lang86846e22014-06-03 15:48:54 -0400339 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
340 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
341 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000342 {
Geoff Lang86846e22014-06-03 15:48:54 -0400343 uint32_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000344 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
345 }
346 }
347 }
348}
349
Geoff Lang86846e22014-06-03 15:48:54 -0400350void LoadRGBA4ToBGRA8(size_t width, size_t height, size_t depth,
351 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
352 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000353{
Geoff Lang86846e22014-06-03 15:48:54 -0400354 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000355 {
Geoff Lang86846e22014-06-03 15:48:54 -0400356 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000357 {
Geoff Lang86846e22014-06-03 15:48:54 -0400358 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
359 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
360 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000361 {
Geoff Lang86846e22014-06-03 15:48:54 -0400362 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000363 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
364 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
365 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
366 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
367 }
368 }
369 }
370}
371
Geoff Lang86846e22014-06-03 15:48:54 -0400372void LoadRGBA4ToRGBA8(size_t width, size_t height, size_t depth,
373 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
374 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000375{
Geoff Lang86846e22014-06-03 15:48:54 -0400376 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000377 {
Geoff Lang86846e22014-06-03 15:48:54 -0400378 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000379 {
Geoff Lang86846e22014-06-03 15:48:54 -0400380 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
381 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
382 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000383 {
Geoff Lang86846e22014-06-03 15:48:54 -0400384 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000385 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
386 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
387 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
388 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
389 }
390 }
391 }
392}
393
Geoff Lang86846e22014-06-03 15:48:54 -0400394void LoadBGRA4ToBGRA8(size_t width, size_t height, size_t depth,
395 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
396 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000397{
Geoff Lang86846e22014-06-03 15:48:54 -0400398 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000399 {
Geoff Lang86846e22014-06-03 15:48:54 -0400400 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000401 {
Geoff Lang86846e22014-06-03 15:48:54 -0400402 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
403 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
404 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000405 {
Geoff Lang86846e22014-06-03 15:48:54 -0400406 uint16_t bgra = source[x];
407 dest[4 * x + 0] = ((bgra & 0xF000) >> 8) | ((bgra & 0xF000) >> 12);
408 dest[4 * x + 1] = ((bgra & 0x0F00) >> 4) | ((bgra & 0x0F00) >> 8);
409 dest[4 * x + 2] = ((bgra & 0x00F0) << 0) | ((bgra & 0x00F0) >> 4);
410 dest[4 * x + 3] = ((bgra & 0x000F) << 4) | ((bgra & 0x000F) >> 0);
411 }
412 }
413 }
414}
415
416void LoadRGB5A1ToBGRA8(size_t width, size_t height, size_t depth,
417 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
418 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
419{
420 for (size_t z = 0; z < depth; z++)
421 {
422 for (size_t y = 0; y < height; y++)
423 {
424 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
425 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
426 for (size_t x = 0; x < width; x++)
427 {
428 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000429 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
430 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
431 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
432 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
433 }
434 }
435 }
436}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000437
Geoff Lang86846e22014-06-03 15:48:54 -0400438void LoadRGB5A1ToRGBA8(size_t width, size_t height, size_t depth,
439 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
440 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
441{
442 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000443 {
Geoff Lang86846e22014-06-03 15:48:54 -0400444 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000445 {
Geoff Lang86846e22014-06-03 15:48:54 -0400446 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
447 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
448 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000449 {
Geoff Lang86846e22014-06-03 15:48:54 -0400450 uint16_t rgba = source[x];
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000451 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
452 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
453 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
454 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
455 }
456 }
457 }
458}
459
Geoff Lang86846e22014-06-03 15:48:54 -0400460
461void LoadBGR5A1ToBGRA8(size_t width, size_t height, size_t depth,
462 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
463 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000464{
Geoff Lang86846e22014-06-03 15:48:54 -0400465 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000466 {
Geoff Lang86846e22014-06-03 15:48:54 -0400467 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000468 {
Geoff Lang86846e22014-06-03 15:48:54 -0400469 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
470 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
471 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000472 {
Geoff Lang86846e22014-06-03 15:48:54 -0400473 uint16_t bgra = source[x];
474 dest[4 * x + 0] = ((bgra & 0xF800) >> 8) | ((bgra & 0xF800) >> 13);
475 dest[4 * x + 1] = ((bgra & 0x07C0) >> 3) | ((bgra & 0x07C0) >> 8);
476 dest[4 * x + 2] = ((bgra & 0x003E) << 2) | ((bgra & 0x003E) >> 3);
477 dest[4 * x + 3] = (bgra & 0x0001) ? 0xFF : 0;
478 }
479 }
480 }
481}
482
483void LoadRGB10A2ToRGBA8(size_t width, size_t height, size_t depth,
484 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
485 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
486{
487 for (size_t z = 0; z < depth; z++)
488 {
489 for (size_t y = 0; y < height; y++)
490 {
491 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
492 uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch);
493 for (size_t x = 0; x < width; x++)
494 {
495 uint32_t rgba = source[x];
shannonwoods@chromium.org5d4468e2013-05-30 00:13:56 +0000496 dest[4 * x + 0] = (rgba & 0x000003FF) >> 2;
497 dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12;
498 dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22;
499 dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55;
500 }
501 }
502 }
503}
504
Geoff Lang86846e22014-06-03 15:48:54 -0400505void LoadRGB16FToRGB9E5(size_t width, size_t height, size_t depth,
506 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
507 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000508{
Geoff Lang86846e22014-06-03 15:48:54 -0400509 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000510 {
Geoff Lang86846e22014-06-03 15:48:54 -0400511 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000512 {
Geoff Lang86846e22014-06-03 15:48:54 -0400513 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
514 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
515 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000516 {
517 dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]),
518 gl::float16ToFloat32(source[x * 3 + 1]),
519 gl::float16ToFloat32(source[x * 3 + 2]));
520 }
521 }
522 }
523}
524
Geoff Lang86846e22014-06-03 15:48:54 -0400525void LoadRGB32FToRGB9E5(size_t width, size_t height, size_t depth,
526 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
527 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000528{
Geoff Lang86846e22014-06-03 15:48:54 -0400529 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000530 {
Geoff Lang86846e22014-06-03 15:48:54 -0400531 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000532 {
Geoff Lang86846e22014-06-03 15:48:54 -0400533 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
534 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
535 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.org92b9cd52013-05-30 00:14:48 +0000536 {
537 dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]);
538 }
539 }
540 }
541}
542
Geoff Lang86846e22014-06-03 15:48:54 -0400543void LoadRGB16FToRG11B10F(size_t width, size_t height, size_t depth,
544 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
545 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000546{
Geoff Lang86846e22014-06-03 15:48:54 -0400547 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000548 {
Geoff Lang86846e22014-06-03 15:48:54 -0400549 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000550 {
Geoff Lang86846e22014-06-03 15:48:54 -0400551 const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch);
552 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
553 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000554 {
555 dest[x] = (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 0])) << 0) |
556 (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 1])) << 11) |
557 (gl::float32ToFloat10(gl::float16ToFloat32(source[x * 3 + 2])) << 22);
558 }
559 }
560 }
561}
562
Geoff Lang86846e22014-06-03 15:48:54 -0400563void LoadRGB32FToRG11B10F(size_t width, size_t height, size_t depth,
564 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
565 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000566{
Geoff Lang86846e22014-06-03 15:48:54 -0400567 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000568 {
Geoff Lang86846e22014-06-03 15:48:54 -0400569 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000570 {
Geoff Lang86846e22014-06-03 15:48:54 -0400571 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
572 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
573 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orga43d8292013-05-30 00:15:50 +0000574 {
575 dest[x] = (gl::float32ToFloat11(source[x * 3 + 0]) << 0) |
576 (gl::float32ToFloat11(source[x * 3 + 1]) << 11) |
577 (gl::float32ToFloat10(source[x * 3 + 2]) << 22);
578 }
579 }
580 }
581}
582
Geoff Lang86846e22014-06-03 15:48:54 -0400583void LoadG8R24ToR24G8(size_t width, size_t height, size_t depth,
584 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
585 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400586{
Geoff Lang86846e22014-06-03 15:48:54 -0400587 for (size_t z = 0; z < depth; z++)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400588 {
Geoff Lang86846e22014-06-03 15:48:54 -0400589 for (size_t y = 0; y < height; y++)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400590 {
Geoff Lang86846e22014-06-03 15:48:54 -0400591 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
592 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
593 for (size_t x = 0; x < width; x++)
Geoff Lang4133f5c2013-10-10 13:51:18 -0400594 {
Geoff Lang86846e22014-06-03 15:48:54 -0400595 uint32_t d = source[x] >> 8;
596 uint8_t s = source[x] & 0xFF;
Geoff Lang5c9a29a2014-02-11 10:26:24 -0500597 dest[x] = d | (s << 24);
Geoff Lang4133f5c2013-10-10 13:51:18 -0400598 }
599 }
600 }
601}
602
Geoff Lang86846e22014-06-03 15:48:54 -0400603void LoadRGB32FToRGBA16F(size_t width, size_t height, size_t depth,
604 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
605 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000606{
Geoff Lang86846e22014-06-03 15:48:54 -0400607 for (size_t z = 0; z < depth; z++)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000608 {
Geoff Lang86846e22014-06-03 15:48:54 -0400609 for (size_t y = 0; y < height; y++)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000610 {
Geoff Lang86846e22014-06-03 15:48:54 -0400611 const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
612 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
613 for (size_t x = 0; x < width; x++)
shannonwoods@chromium.orgde7e6a22013-05-30 00:16:46 +0000614 {
615 dest[x * 4 + 0] = gl::float32ToFloat16(source[x * 3 + 0]);
616 dest[x * 4 + 1] = gl::float32ToFloat16(source[x * 3 + 1]);
617 dest[x * 4 + 2] = gl::float32ToFloat16(source[x * 3 + 2]);
618 dest[x * 4 + 3] = gl::Float16One;
619 }
620 }
621 }
622}
623
Geoff Lang86846e22014-06-03 15:48:54 -0400624void LoadR32ToR16(size_t width, size_t height, size_t depth,
625 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
626 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lang87465462013-06-17 16:28:54 -0400627{
Geoff Lang86846e22014-06-03 15:48:54 -0400628 for (size_t z = 0; z < depth; z++)
Geoff Lang87465462013-06-17 16:28:54 -0400629 {
Geoff Lang86846e22014-06-03 15:48:54 -0400630 for (size_t y = 0; y < height; y++)
Geoff Lang87465462013-06-17 16:28:54 -0400631 {
Geoff Lang86846e22014-06-03 15:48:54 -0400632 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
633 uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch);
634 for (size_t x = 0; x < width; x++)
Geoff Lang87465462013-06-17 16:28:54 -0400635 {
636 dest[x] = source[x] >> 16;
637 }
638 }
639 }
640}
641
Geoff Lang86846e22014-06-03 15:48:54 -0400642void LoadR32ToR24G8(size_t width, size_t height, size_t depth,
643 const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch,
644 uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch)
Geoff Lange4a492b2014-06-19 14:14:41 -0400645{
Geoff Lang86846e22014-06-03 15:48:54 -0400646 for (size_t z = 0; z < depth; z++)
Geoff Lange4a492b2014-06-19 14:14:41 -0400647 {
Geoff Lang86846e22014-06-03 15:48:54 -0400648 for (size_t y = 0; y < height; y++)
Geoff Lange4a492b2014-06-19 14:14:41 -0400649 {
Geoff Lang86846e22014-06-03 15:48:54 -0400650 const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch);
651 uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch);
Geoff Lange4a492b2014-06-19 14:14:41 -0400652
Geoff Lang86846e22014-06-03 15:48:54 -0400653 for (size_t x = 0; x < width; x++)
Geoff Lange4a492b2014-06-19 14:14:41 -0400654 {
655 dest[x] = source[x] >> 8;
656 }
657 }
658 }
659}
660
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000661}