blob: b5e768ca23b92c3d189490a945c3014256f59fc2 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00002//
3// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
daniel@transgaming.com4ba24062012-12-20 20:54:24 +00008// Image.h: Implements the rx::Image class, an abstract base class for the
9// renderer-specific classes which will define the interface to the underlying
10// surfaces or resources.
11
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000012#include "libGLESv2/renderer/Image.h"
13
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000014namespace rx
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000015{
daniel@transgaming.com0ad830b2012-10-31 19:52:12 +000016
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000017Image::Image()
18{
19 mWidth = 0;
20 mHeight = 0;
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000021 mDepth = 0;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000022 mInternalFormat = GL_NONE;
daniel@transgaming.com20d36662012-10-31 19:51:43 +000023 mActualFormat = GL_NONE;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000024}
25
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000026void Image::loadAlphaDataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
27 int inputRowPitch, int inputDepthPitch, const void *input,
28 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000029{
30 const unsigned char *source = NULL;
31 unsigned char *dest = NULL;
32
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000033 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000034 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000035 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000036 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000037 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
38 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000039 for (int x = 0; x < width; x++)
40 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000041 dest[4 * x + 0] = 0;
42 dest[4 * x + 1] = 0;
43 dest[4 * x + 2] = 0;
44 dest[4 * x + 3] = source[x];
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000045 }
46 }
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000047 }
48}
49
50void Image::loadAlphaDataToNative(GLsizei width, GLsizei height, GLsizei depth,
51 int inputRowPitch, int inputDepthPitch, const void *input,
52 size_t outputRowPitch, size_t outputDepthPitch, void *output)
53{
54 const unsigned char *source = NULL;
55 unsigned char *dest = NULL;
56
57 for (int z = 0; z < depth; z++)
58 {
59 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000060 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000061 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
62 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000063 memcpy(dest, source, width);
64 }
65 }
66}
67
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000068void Image::loadAlphaFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
69 int inputRowPitch, int inputDepthPitch, const void *input,
70 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000071{
72 const float *source = NULL;
73 float *dest = NULL;
74
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000075 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000076 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000077 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000078 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000079 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
80 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
81 for (int x = 0; x < width; x++)
82 {
83 dest[4 * x + 0] = 0;
84 dest[4 * x + 1] = 0;
85 dest[4 * x + 2] = 0;
86 dest[4 * x + 3] = source[x];
87 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000088 }
89 }
90}
91
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000092void Image::loadAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
93 int inputRowPitch, int inputDepthPitch, const void *input,
94 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000095{
96 const unsigned short *source = NULL;
97 unsigned short *dest = NULL;
98
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000099 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000100 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000101 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000102 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000103 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
104 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
105 for (int x = 0; x < width; x++)
106 {
107 dest[4 * x + 0] = 0;
108 dest[4 * x + 1] = 0;
109 dest[4 * x + 2] = 0;
110 dest[4 * x + 3] = source[x];
111 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000112 }
113 }
114}
115
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000116void Image::loadLuminanceDataToNativeOrBGRA(GLsizei width, GLsizei height, GLsizei depth,
117 int inputRowPitch, int inputDepthPitch, const void *input,
118 size_t outputRowPitch, size_t outputDepthPitch, void *output,
119 bool native)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000120{
121 const unsigned char *source = NULL;
122 unsigned char *dest = NULL;
123
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000124 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000125 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000126 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000127 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000128 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
129 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
130
131 if (!native) // BGRA8 destination format
132 {
133 for (int x = 0; x < width; x++)
134 {
135 dest[4 * x + 0] = source[x];
136 dest[4 * x + 1] = source[x];
137 dest[4 * x + 2] = source[x];
138 dest[4 * x + 3] = 0xFF;
139 }
140 }
141 else // L8 destination format
142 {
143 memcpy(dest, source, width);
144 }
145 }
146 }
147}
148
149void Image::loadLuminanceFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
150 int inputRowPitch, int inputDepthPitch, const void *input,
151 size_t outputRowPitch, size_t outputDepthPitch, void *output)
152{
153 const float *source = NULL;
154 float *dest = NULL;
155
156 for (int z = 0; z < depth; z++)
157 {
158 for (int y = 0; y < height; y++)
159 {
160 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
161 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
162 for (int x = 0; x < width; x++)
163 {
164 dest[4 * x + 0] = source[x];
165 dest[4 * x + 1] = source[x];
166 dest[4 * x + 2] = source[x];
167 dest[4 * x + 3] = 1.0f;
168 }
169 }
170 }
171}
172
173void Image::loadLuminanceFloatDataToRGB(GLsizei width, GLsizei height, GLsizei depth,
174 int inputRowPitch, int inputDepthPitch, const void *input,
175 size_t outputRowPitch, size_t outputDepthPitch, void *output)
176{
177 const float *source = NULL;
178 float *dest = NULL;
179
180 for (int z = 0; z < depth; z++)
181 {
182 for (int y = 0; y < height; y++)
183 {
184 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
185 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
186 for (int x = 0; x < width; x++)
187 {
188 dest[3 * x + 0] = source[x];
189 dest[3 * x + 1] = source[x];
190 dest[3 * x + 2] = source[x];
191 }
192 }
193 }
194}
195
196void Image::loadLuminanceHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
197 int inputRowPitch, int inputDepthPitch, const void *input,
198 size_t outputRowPitch, size_t outputDepthPitch, void *output)
199{
200 const unsigned short *source = NULL;
201 unsigned short *dest = NULL;
202
203 for (int z = 0; z < depth; z++)
204 {
205 for (int y = 0; y < height; y++)
206 {
207 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
208 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
209 for (int x = 0; x < width; x++)
210 {
211 dest[4 * x + 0] = source[x];
212 dest[4 * x + 1] = source[x];
213 dest[4 * x + 2] = source[x];
214 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
215 }
216 }
217 }
218}
219
220void Image::loadLuminanceAlphaDataToNativeOrBGRA(GLsizei width, GLsizei height, GLsizei depth,
221 int inputRowPitch, int inputDepthPitch, const void *input,
222 size_t outputRowPitch, size_t outputDepthPitch, void *output,
223 bool native)
224{
225 const unsigned char *source = NULL;
226 unsigned char *dest = NULL;
227
228 for (int z = 0; z < depth; z++)
229 {
230 for (int y = 0; y < height; y++)
231 {
232 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
233 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
234
235 if (!native) // BGRA8 destination format
236 {
237 for (int x = 0; x < width; x++)
238 {
239 dest[4 * x + 0] = source[2*x+0];
240 dest[4 * x + 1] = source[2*x+0];
241 dest[4 * x + 2] = source[2*x+0];
242 dest[4 * x + 3] = source[2*x+1];
243 }
244 }
245 else
246 {
247 memcpy(dest, source, width * 2);
248 }
249 }
250 }
251}
252
253void Image::loadLuminanceAlphaFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
254 int inputRowPitch, int inputDepthPitch, const void *input,
255 size_t outputRowPitch, size_t outputDepthPitch, void *output)
256{
257 const float *source = NULL;
258 float *dest = NULL;
259
260 for (int z = 0; z < depth; z++)
261 {
262 for (int y = 0; y < height; y++)
263 {
264 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
265 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000266 for (int x = 0; x < width; x++)
267 {
268 dest[4 * x + 0] = source[2*x+0];
269 dest[4 * x + 1] = source[2*x+0];
270 dest[4 * x + 2] = source[2*x+0];
271 dest[4 * x + 3] = source[2*x+1];
272 }
273 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000274 }
275}
276
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000277void Image::loadLuminanceAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
278 int inputRowPitch, int inputDepthPitch, const void *input,
279 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000280{
281 const unsigned short *source = NULL;
282 unsigned short *dest = NULL;
283
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000284 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000285 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000286 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000287 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000288 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
289 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
290 for (int x = 0; x < width; x++)
291 {
292 dest[4 * x + 0] = source[2*x+0];
293 dest[4 * x + 1] = source[2*x+0];
294 dest[4 * x + 2] = source[2*x+0];
295 dest[4 * x + 3] = source[2*x+1];
296 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000297 }
298 }
299}
300
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000301void Image::loadRGBUByteDataToBGRX(GLsizei width, GLsizei height, GLsizei depth,
302 int inputRowPitch, int inputDepthPitch, const void *input,
303 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000304{
305 const unsigned char *source = NULL;
306 unsigned char *dest = NULL;
307
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000308 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000309 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000310 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000311 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000312 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
313 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
314 for (int x = 0; x < width; x++)
315 {
316 dest[4 * x + 0] = source[x * 3 + 2];
317 dest[4 * x + 1] = source[x * 3 + 1];
318 dest[4 * x + 2] = source[x * 3 + 0];
319 dest[4 * x + 3] = 0xFF;
320 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000321 }
322 }
323}
324
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000325void Image::loadRGBUByteDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
326 int inputRowPitch, int inputDepthPitch, const void *input,
327 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000328{
329 const unsigned char *source = NULL;
330 unsigned char *dest = NULL;
331
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000332 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000333 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000334 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000335 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000336 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
337 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
338 for (int x = 0; x < width; x++)
339 {
340 dest[4 * x + 0] = source[x * 3 + 0];
341 dest[4 * x + 1] = source[x * 3 + 1];
342 dest[4 * x + 2] = source[x * 3 + 2];
343 dest[4 * x + 3] = 0xFF;
344 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000345 }
346 }
347}
348
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000349void Image::loadRGB565DataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
350 int inputRowPitch, int inputDepthPitch, const void *input,
351 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000352{
353 const unsigned short *source = NULL;
354 unsigned char *dest = NULL;
355
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000356 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000357 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000358 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000359 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000360 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
361 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
362 for (int x = 0; x < width; x++)
363 {
364 unsigned short rgba = source[x];
365 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
366 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
367 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
368 dest[4 * x + 3] = 0xFF;
369 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000370 }
371 }
372}
373
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000374void Image::loadRGB565DataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
375 int inputRowPitch, int inputDepthPitch, const void *input,
376 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000377{
378 const unsigned short *source = NULL;
379 unsigned char *dest = NULL;
380
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000381 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000382 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000383 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000384 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000385 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
386 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
387 for (int x = 0; x < width; x++)
388 {
389 unsigned short rgba = source[x];
390 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
391 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
392 dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
393 dest[4 * x + 3] = 0xFF;
394 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000395 }
396 }
397}
398
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000399void Image::loadRGBFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
400 int inputRowPitch, int inputDepthPitch, const void *input,
401 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000402{
403 const float *source = NULL;
404 float *dest = NULL;
405
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000406 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000407 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000408 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000409 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000410 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
411 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
412 for (int x = 0; x < width; x++)
413 {
414 dest[4 * x + 0] = source[x * 3 + 0];
415 dest[4 * x + 1] = source[x * 3 + 1];
416 dest[4 * x + 2] = source[x * 3 + 2];
417 dest[4 * x + 3] = 1.0f;
418 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000419 }
420 }
421}
422
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000423void Image::loadRGBFloatDataToNative(GLsizei width, GLsizei height, GLsizei depth,
424 int inputRowPitch, int inputDepthPitch, const void *input,
425 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000426{
427 const float *source = NULL;
428 float *dest = NULL;
429
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000430 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000431 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000432 for (int y = 0; y < height; y++)
433 {
434 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
435 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
436 memcpy(dest, source, width * 12);
437 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000438 }
439}
440
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000441void Image::loadRGBHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
442 int inputRowPitch, int inputDepthPitch, const void *input,
443 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000444{
445 const unsigned short *source = NULL;
446 unsigned short *dest = NULL;
447
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000448 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000449 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000450 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000451 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000452 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
453 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
454 for (int x = 0; x < width; x++)
455 {
456 dest[4 * x + 0] = source[x * 3 + 0];
457 dest[4 * x + 1] = source[x * 3 + 1];
458 dest[4 * x + 2] = source[x * 3 + 2];
459 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
460 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000461 }
462 }
463}
464
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000465void Image::loadRGBAUByteDataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
466 int inputRowPitch, int inputDepthPitch, const void *input,
467 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000468{
469 const unsigned int *source = NULL;
470 unsigned int *dest = NULL;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000471
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000472 for (int z = 0; z < depth; z++)
473 {
474 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000475 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000476 source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
477 dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
478
479 for (int x = 0; x < width; x++)
480 {
481 unsigned int rgba = source[x];
482 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
483 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000484 }
485 }
486}
487
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000488void Image::loadRGBAUByteDataToNative(GLsizei width, GLsizei height, GLsizei depth,
489 int inputRowPitch, int inputDepthPitch, const void *input,
490 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000491{
492 const unsigned int *source = NULL;
493 unsigned int *dest = NULL;
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000494
495 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000496 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000497 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000498 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000499 source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
500 dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
501
502 memcpy(dest, source, width * 4);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000503 }
504 }
505}
506
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000507void Image::loadRGBA4444DataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
508 int inputRowPitch, int inputDepthPitch, const void *input,
509 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000510{
511 const unsigned short *source = NULL;
512 unsigned char *dest = NULL;
513
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000514 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000515 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000516 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000517 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000518 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
519 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
520 for (int x = 0; x < width; x++)
521 {
522 unsigned short rgba = source[x];
523 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
524 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
525 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
526 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
527 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000528 }
529 }
530}
531
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000532void Image::loadRGBA4444DataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
533 int inputRowPitch, int inputDepthPitch, const void *input,
534 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000535{
536 const unsigned short *source = NULL;
537 unsigned char *dest = NULL;
538
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000539 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000540 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000541 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000542 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000543 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
544 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
545 for (int x = 0; x < width; x++)
546 {
547 unsigned short rgba = source[x];
548 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
549 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
550 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
551 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
552 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000553 }
554 }
555}
556
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000557void Image::loadRGBA5551DataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
558 int inputRowPitch, int inputDepthPitch, const void *input,
559 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000560{
561 const unsigned short *source = NULL;
562 unsigned char *dest = NULL;
563
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000564 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000565 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000566 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000567 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000568 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
569 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
570 for (int x = 0; x < width; x++)
571 {
572 unsigned short rgba = source[x];
573 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
574 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
575 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
576 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
577 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000578 }
579 }
580}
581
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000582void Image::loadRGBA5551DataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
583 int inputRowPitch, int inputDepthPitch, const void *input,
584 size_t outputRowPitch, size_t outputDepthPitch, void *output)
585{
586 const unsigned short *source = NULL;
587 unsigned char *dest = NULL;
588
589 for (int z = 0; z < depth; z++)
590 {
591 for (int y = 0; y < height; y++)
592 {
593 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
594 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
595 for (int x = 0; x < width; x++)
596 {
597 unsigned short rgba = source[x];
598 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
599 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
600 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
601 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
602 }
603 }
604 }
605}
606
607void Image::loadRGBAFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
608 int inputRowPitch, int inputDepthPitch, const void *input,
609 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000610{
611 const float *source = NULL;
612 float *dest = NULL;
613
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000614 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000615 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000616 for (int y = 0; y < height; y++)
617 {
618 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
619 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
620 memcpy(dest, source, width * 16);
621 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000622 }
623}
624
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000625void Image::loadRGBAHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
626 int inputRowPitch, int inputDepthPitch, const void *input,
627 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000628{
629 const unsigned char *source = NULL;
630 unsigned char *dest = NULL;
631
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000632 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000633 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000634 for (int y = 0; y < height; y++)
635 {
636 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
637 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
638 memcpy(dest, source, width * 8);
639 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000640 }
641}
642
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000643void Image::loadBGRADataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
644 int inputRowPitch, int inputDepthPitch, const void *input,
645 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000646{
647 const unsigned char *source = NULL;
648 unsigned char *dest = NULL;
649
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000650 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000651 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000652 for (int y = 0; y < height; y++)
653 {
654 source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
655 dest = static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch;
656 memcpy(dest, source, width*4);
657 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000658 }
659}
660
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000661}