blob: 27f15b07b5ccce4257411224296df43a4621f64d [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.com0fcf2a62013-04-13 03:42:44 +000026template <typename T>
27inline static T *offsetDataPointer(void *data, int y, int z, int rowPitch, int depthPitch)
28{
29 return reinterpret_cast<T*>(reinterpret_cast<unsigned char*>(data) + (y * rowPitch) + (z * depthPitch));
30}
31
32template <typename T>
33inline static const T *offsetDataPointer(const void *data, int y, int z, int rowPitch, int depthPitch)
34{
35 return reinterpret_cast<const T*>(reinterpret_cast<const unsigned char*>(data) + (y * rowPitch) + (z * depthPitch));
36}
37
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000038void Image::loadAlphaDataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
39 int inputRowPitch, int inputDepthPitch, const void *input,
40 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000041{
42 const unsigned char *source = NULL;
43 unsigned char *dest = NULL;
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +000044
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000045 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000046 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000047 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000048 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +000049 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
50 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000051 for (int x = 0; x < width; x++)
52 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000053 dest[4 * x + 0] = 0;
54 dest[4 * x + 1] = 0;
55 dest[4 * x + 2] = 0;
56 dest[4 * x + 3] = source[x];
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000057 }
58 }
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000059 }
60}
61
62void Image::loadAlphaDataToNative(GLsizei width, GLsizei height, GLsizei depth,
63 int inputRowPitch, int inputDepthPitch, const void *input,
64 size_t outputRowPitch, size_t outputDepthPitch, void *output)
65{
66 const unsigned char *source = NULL;
67 unsigned char *dest = NULL;
68
69 for (int z = 0; z < depth; z++)
70 {
71 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000072 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +000073 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
74 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000075 memcpy(dest, source, width);
76 }
77 }
78}
79
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000080void Image::loadAlphaFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
81 int inputRowPitch, int inputDepthPitch, const void *input,
82 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000083{
84 const float *source = NULL;
85 float *dest = NULL;
86
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000087 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000088 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000089 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000090 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +000091 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
92 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +000093 for (int x = 0; x < width; x++)
94 {
95 dest[4 * x + 0] = 0;
96 dest[4 * x + 1] = 0;
97 dest[4 * x + 2] = 0;
98 dest[4 * x + 3] = source[x];
99 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000100 }
101 }
102}
103
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000104void Image::loadAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
105 int inputRowPitch, int inputDepthPitch, const void *input,
106 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000107{
108 const unsigned short *source = NULL;
109 unsigned short *dest = NULL;
110
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000111 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000112 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000113 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000114 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000115 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
116 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000117 for (int x = 0; x < width; x++)
118 {
119 dest[4 * x + 0] = 0;
120 dest[4 * x + 1] = 0;
121 dest[4 * x + 2] = 0;
122 dest[4 * x + 3] = source[x];
123 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000124 }
125 }
126}
127
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000128void Image::loadLuminanceDataToNativeOrBGRA(GLsizei width, GLsizei height, GLsizei depth,
129 int inputRowPitch, int inputDepthPitch, const void *input,
130 size_t outputRowPitch, size_t outputDepthPitch, void *output,
131 bool native)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000132{
133 const unsigned char *source = NULL;
134 unsigned char *dest = NULL;
135
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000136 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000137 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000138 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000139 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000140 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
141 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000142 if (!native) // BGRA8 destination format
143 {
144 for (int x = 0; x < width; x++)
145 {
146 dest[4 * x + 0] = source[x];
147 dest[4 * x + 1] = source[x];
148 dest[4 * x + 2] = source[x];
149 dest[4 * x + 3] = 0xFF;
150 }
151 }
152 else // L8 destination format
153 {
154 memcpy(dest, source, width);
155 }
156 }
157 }
158}
159
160void Image::loadLuminanceFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
161 int inputRowPitch, int inputDepthPitch, const void *input,
162 size_t outputRowPitch, size_t outputDepthPitch, void *output)
163{
164 const float *source = NULL;
165 float *dest = NULL;
166
167 for (int z = 0; z < depth; z++)
168 {
169 for (int y = 0; y < height; y++)
170 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000171 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
172 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000173 for (int x = 0; x < width; x++)
174 {
175 dest[4 * x + 0] = source[x];
176 dest[4 * x + 1] = source[x];
177 dest[4 * x + 2] = source[x];
178 dest[4 * x + 3] = 1.0f;
179 }
180 }
181 }
182}
183
184void Image::loadLuminanceFloatDataToRGB(GLsizei width, GLsizei height, GLsizei depth,
185 int inputRowPitch, int inputDepthPitch, const void *input,
186 size_t outputRowPitch, size_t outputDepthPitch, void *output)
187{
188 const float *source = NULL;
189 float *dest = NULL;
190
191 for (int z = 0; z < depth; z++)
192 {
193 for (int y = 0; y < height; y++)
194 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000195 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
196 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000197 for (int x = 0; x < width; x++)
198 {
199 dest[3 * x + 0] = source[x];
200 dest[3 * x + 1] = source[x];
201 dest[3 * x + 2] = source[x];
202 }
203 }
204 }
205}
206
207void Image::loadLuminanceHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
208 int inputRowPitch, int inputDepthPitch, const void *input,
209 size_t outputRowPitch, size_t outputDepthPitch, void *output)
210{
211 const unsigned short *source = NULL;
212 unsigned short *dest = NULL;
213
214 for (int z = 0; z < depth; z++)
215 {
216 for (int y = 0; y < height; y++)
217 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000218 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
219 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000220 for (int x = 0; x < width; x++)
221 {
222 dest[4 * x + 0] = source[x];
223 dest[4 * x + 1] = source[x];
224 dest[4 * x + 2] = source[x];
225 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
226 }
227 }
228 }
229}
230
231void Image::loadLuminanceAlphaDataToNativeOrBGRA(GLsizei width, GLsizei height, GLsizei depth,
232 int inputRowPitch, int inputDepthPitch, const void *input,
233 size_t outputRowPitch, size_t outputDepthPitch, void *output,
234 bool native)
235{
236 const unsigned char *source = NULL;
237 unsigned char *dest = NULL;
238
239 for (int z = 0; z < depth; z++)
240 {
241 for (int y = 0; y < height; y++)
242 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000243 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
244 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000245
246 if (!native) // BGRA8 destination format
247 {
248 for (int x = 0; x < width; x++)
249 {
250 dest[4 * x + 0] = source[2*x+0];
251 dest[4 * x + 1] = source[2*x+0];
252 dest[4 * x + 2] = source[2*x+0];
253 dest[4 * x + 3] = source[2*x+1];
254 }
255 }
256 else
257 {
258 memcpy(dest, source, width * 2);
259 }
260 }
261 }
262}
263
264void Image::loadLuminanceAlphaFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
265 int inputRowPitch, int inputDepthPitch, const void *input,
266 size_t outputRowPitch, size_t outputDepthPitch, void *output)
267{
268 const float *source = NULL;
269 float *dest = NULL;
270
271 for (int z = 0; z < depth; z++)
272 {
273 for (int y = 0; y < height; y++)
274 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000275 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
276 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000277 for (int x = 0; x < width; x++)
278 {
279 dest[4 * x + 0] = source[2*x+0];
280 dest[4 * x + 1] = source[2*x+0];
281 dest[4 * x + 2] = source[2*x+0];
282 dest[4 * x + 3] = source[2*x+1];
283 }
284 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000285 }
286}
287
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000288void Image::loadLuminanceAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
289 int inputRowPitch, int inputDepthPitch, const void *input,
290 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000291{
292 const unsigned short *source = NULL;
293 unsigned short *dest = NULL;
294
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000295 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000296 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000297 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000298 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000299 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
300 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000301 for (int x = 0; x < width; x++)
302 {
303 dest[4 * x + 0] = source[2*x+0];
304 dest[4 * x + 1] = source[2*x+0];
305 dest[4 * x + 2] = source[2*x+0];
306 dest[4 * x + 3] = source[2*x+1];
307 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000308 }
309 }
310}
311
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000312void Image::loadRGBUByteDataToBGRX(GLsizei width, GLsizei height, GLsizei depth,
313 int inputRowPitch, int inputDepthPitch, const void *input,
314 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000315{
316 const unsigned char *source = NULL;
317 unsigned char *dest = NULL;
318
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000319 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000320 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000321 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000322 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000323 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
324 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000325 for (int x = 0; x < width; x++)
326 {
327 dest[4 * x + 0] = source[x * 3 + 2];
328 dest[4 * x + 1] = source[x * 3 + 1];
329 dest[4 * x + 2] = source[x * 3 + 0];
330 dest[4 * x + 3] = 0xFF;
331 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000332 }
333 }
334}
335
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000336void Image::loadRGBUByteDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
337 int inputRowPitch, int inputDepthPitch, const void *input,
338 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000339{
340 const unsigned char *source = NULL;
341 unsigned char *dest = NULL;
342
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000343 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000344 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000345 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000346 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000347 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
348 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000349 for (int x = 0; x < width; x++)
350 {
351 dest[4 * x + 0] = source[x * 3 + 0];
352 dest[4 * x + 1] = source[x * 3 + 1];
353 dest[4 * x + 2] = source[x * 3 + 2];
354 dest[4 * x + 3] = 0xFF;
355 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000356 }
357 }
358}
359
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000360void Image::loadRGB565DataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
361 int inputRowPitch, int inputDepthPitch, const void *input,
362 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000363{
364 const unsigned short *source = NULL;
365 unsigned char *dest = NULL;
366
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000367 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000368 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000369 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000370 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000371 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
372 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000373 for (int x = 0; x < width; x++)
374 {
375 unsigned short rgba = source[x];
376 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
377 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
378 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
379 dest[4 * x + 3] = 0xFF;
380 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000381 }
382 }
383}
384
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000385void Image::loadRGB565DataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
386 int inputRowPitch, int inputDepthPitch, const void *input,
387 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000388{
389 const unsigned short *source = NULL;
390 unsigned char *dest = NULL;
391
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000392 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000393 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000394 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000395 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000396 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
397 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000398 for (int x = 0; x < width; x++)
399 {
400 unsigned short rgba = source[x];
401 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
402 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
403 dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
404 dest[4 * x + 3] = 0xFF;
405 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000406 }
407 }
408}
409
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000410void Image::loadRGBFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
411 int inputRowPitch, int inputDepthPitch, const void *input,
412 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000413{
414 const float *source = NULL;
415 float *dest = NULL;
416
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000417 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000418 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000419 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000420 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000421 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
422 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000423 for (int x = 0; x < width; x++)
424 {
425 dest[4 * x + 0] = source[x * 3 + 0];
426 dest[4 * x + 1] = source[x * 3 + 1];
427 dest[4 * x + 2] = source[x * 3 + 2];
428 dest[4 * x + 3] = 1.0f;
429 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000430 }
431 }
432}
433
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000434void Image::loadRGBFloatDataToNative(GLsizei width, GLsizei height, GLsizei depth,
435 int inputRowPitch, int inputDepthPitch, const void *input,
436 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000437{
438 const float *source = NULL;
439 float *dest = NULL;
440
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000441 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000442 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000443 for (int y = 0; y < height; y++)
444 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000445 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
446 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000447 memcpy(dest, source, width * 12);
448 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000449 }
450}
451
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000452void Image::loadRGBHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
453 int inputRowPitch, int inputDepthPitch, const void *input,
454 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000455{
456 const unsigned short *source = NULL;
457 unsigned short *dest = NULL;
458
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000459 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000460 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000461 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000462 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000463 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
464 dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000465 for (int x = 0; x < width; x++)
466 {
467 dest[4 * x + 0] = source[x * 3 + 0];
468 dest[4 * x + 1] = source[x * 3 + 1];
469 dest[4 * x + 2] = source[x * 3 + 2];
470 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
471 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000472 }
473 }
474}
475
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000476void Image::loadRGBAUByteDataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
477 int inputRowPitch, int inputDepthPitch, const void *input,
478 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000479{
480 const unsigned int *source = NULL;
481 unsigned int *dest = NULL;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000482
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000483 for (int z = 0; z < depth; z++)
484 {
485 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000486 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000487 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
488 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000489
490 for (int x = 0; x < width; x++)
491 {
492 unsigned int rgba = source[x];
493 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
494 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000495 }
496 }
497}
498
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000499void Image::loadRGBAUByteDataToNative(GLsizei width, GLsizei height, GLsizei depth,
500 int inputRowPitch, int inputDepthPitch, const void *input,
501 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000502{
503 const unsigned int *source = NULL;
504 unsigned int *dest = NULL;
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000505
506 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000507 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000508 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000509 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000510 source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch);
511 dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000512
513 memcpy(dest, source, width * 4);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000514 }
515 }
516}
517
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000518void Image::loadRGBA4444DataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
519 int inputRowPitch, int inputDepthPitch, const void *input,
520 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000521{
522 const unsigned short *source = NULL;
523 unsigned char *dest = NULL;
524
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000525 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000526 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000527 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000528 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000529 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
530 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000531 for (int x = 0; x < width; x++)
532 {
533 unsigned short rgba = source[x];
534 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
535 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
536 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
537 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
538 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000539 }
540 }
541}
542
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000543void Image::loadRGBA4444DataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
544 int inputRowPitch, int inputDepthPitch, const void *input,
545 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000546{
547 const unsigned short *source = NULL;
548 unsigned char *dest = NULL;
549
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000550 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000551 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000552 for (int y = 0; y < height; y++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000553 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000554 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
555 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000556 for (int x = 0; x < width; x++)
557 {
558 unsigned short rgba = source[x];
559 dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
560 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
561 dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
562 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
563 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000564 }
565 }
566}
567
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000568void Image::loadRGBA5551DataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
569 int inputRowPitch, int inputDepthPitch, const void *input,
570 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000571{
572 const unsigned short *source = NULL;
573 unsigned char *dest = NULL;
574
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000575 for (int z = 0; z < depth; z++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000576 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000577 for (int y = 0; y < height; y++)
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000578 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000579 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
580 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000581 for (int x = 0; x < width; x++)
582 {
583 unsigned short rgba = source[x];
584 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
585 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
586 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
587 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
588 }
daniel@transgaming.com005979d2012-12-20 21:11:29 +0000589 }
590 }
591}
592
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000593void Image::loadRGBA5551DataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
594 int inputRowPitch, int inputDepthPitch, const void *input,
595 size_t outputRowPitch, size_t outputDepthPitch, void *output)
596{
597 const unsigned short *source = NULL;
598 unsigned char *dest = NULL;
599
600 for (int z = 0; z < depth; z++)
601 {
602 for (int y = 0; y < height; y++)
603 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000604 source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch);
605 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000606 for (int x = 0; x < width; x++)
607 {
608 unsigned short rgba = source[x];
609 dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
610 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
611 dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
612 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
613 }
614 }
615 }
616}
617
618void Image::loadRGBAFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
619 int inputRowPitch, int inputDepthPitch, const void *input,
620 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000621{
622 const float *source = NULL;
623 float *dest = NULL;
624
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000625 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000626 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000627 for (int y = 0; y < height; y++)
628 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000629 source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch);
630 dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000631 memcpy(dest, source, width * 16);
632 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000633 }
634}
635
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000636void Image::loadRGBAHalfFloatDataToRGBA(GLsizei width, GLsizei height, GLsizei depth,
637 int inputRowPitch, int inputDepthPitch, const void *input,
638 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000639{
640 const unsigned char *source = NULL;
641 unsigned char *dest = NULL;
642
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000643 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000644 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000645 for (int y = 0; y < height; y++)
646 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000647 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
648 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000649 memcpy(dest, source, width * 8);
650 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000651 }
652}
653
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000654void Image::loadBGRADataToBGRA(GLsizei width, GLsizei height, GLsizei depth,
655 int inputRowPitch, int inputDepthPitch, const void *input,
656 size_t outputRowPitch, size_t outputDepthPitch, void *output)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000657{
658 const unsigned char *source = NULL;
659 unsigned char *dest = NULL;
660
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000661 for (int z = 0; z < depth; z++)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000662 {
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000663 for (int y = 0; y < height; y++)
664 {
shannon.woods%transgaming.com@gtempaccount.com0fcf2a62013-04-13 03:42:44 +0000665 source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch);
666 dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000667 memcpy(dest, source, width*4);
668 }
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000669 }
670}
671
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000672}