daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
daniel@transgaming.com | 4ba2406 | 2012-12-20 20:54:24 +0000 | [diff] [blame] | 7 | // Image.h: Implements the rx::Image class, an abstract base class for the |
| 8 | // renderer-specific classes which will define the interface to the underlying |
| 9 | // surfaces or resources. |
| 10 | |
| 11 | #include <GLES2/gl2.h> |
| 12 | #include <string.h> |
| 13 | #include <stdlib.h> |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 14 | |
| 15 | #include "libGLESv2/renderer/Image.h" |
| 16 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 17 | namespace rx |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 18 | { |
daniel@transgaming.com | 0ad830b | 2012-10-31 19:52:12 +0000 | [diff] [blame] | 19 | |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 20 | Image::Image() |
| 21 | { |
| 22 | mWidth = 0; |
| 23 | mHeight = 0; |
| 24 | mInternalFormat = GL_NONE; |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 25 | mActualFormat = GL_NONE; |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 26 | } |
| 27 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 28 | void Image::loadAlphaDataToBGRA(GLsizei width, GLsizei height, |
| 29 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 30 | { |
| 31 | const unsigned char *source = NULL; |
| 32 | unsigned char *dest = NULL; |
| 33 | |
| 34 | for (int y = 0; y < height; y++) |
| 35 | { |
| 36 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 37 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 38 | for (int x = 0; x < width; x++) |
| 39 | { |
| 40 | dest[4 * x + 0] = 0; |
| 41 | dest[4 * x + 1] = 0; |
| 42 | dest[4 * x + 2] = 0; |
| 43 | dest[4 * x + 3] = source[x]; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
daniel@transgaming.com | 26041c9 | 2013-01-11 04:08:58 +0000 | [diff] [blame] | 48 | void Image::loadAlphaDataToNative(GLsizei width, GLsizei height, |
| 49 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 50 | { |
| 51 | const unsigned char *source = NULL; |
| 52 | unsigned char *dest = NULL; |
| 53 | |
| 54 | for (int y = 0; y < height; y++) |
| 55 | { |
| 56 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 57 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 58 | memcpy(dest, source, width); |
| 59 | } |
| 60 | } |
| 61 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 62 | void Image::loadAlphaFloatDataToRGBA(GLsizei width, GLsizei height, |
| 63 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 64 | { |
| 65 | const float *source = NULL; |
| 66 | float *dest = NULL; |
| 67 | |
| 68 | for (int y = 0; y < height; y++) |
| 69 | { |
| 70 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 71 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 72 | for (int x = 0; x < width; x++) |
| 73 | { |
| 74 | dest[4 * x + 0] = 0; |
| 75 | dest[4 * x + 1] = 0; |
| 76 | dest[4 * x + 2] = 0; |
| 77 | dest[4 * x + 3] = source[x]; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 82 | void Image::loadAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, |
| 83 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 84 | { |
| 85 | const unsigned short *source = NULL; |
| 86 | unsigned short *dest = NULL; |
| 87 | |
| 88 | for (int y = 0; y < height; y++) |
| 89 | { |
| 90 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 91 | dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 92 | for (int x = 0; x < width; x++) |
| 93 | { |
| 94 | dest[4 * x + 0] = 0; |
| 95 | dest[4 * x + 1] = 0; |
| 96 | dest[4 * x + 2] = 0; |
| 97 | dest[4 * x + 3] = source[x]; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 102 | void Image::loadLuminanceDataToNativeOrBGRA(GLsizei width, GLsizei height, |
| 103 | int inputPitch, const void *input, size_t outputPitch, void *output, bool native) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 104 | { |
| 105 | const unsigned char *source = NULL; |
| 106 | unsigned char *dest = NULL; |
| 107 | |
| 108 | for (int y = 0; y < height; y++) |
| 109 | { |
| 110 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 111 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 112 | |
| 113 | if (!native) // BGRA8 destination format |
| 114 | { |
| 115 | for (int x = 0; x < width; x++) |
| 116 | { |
| 117 | dest[4 * x + 0] = source[x]; |
| 118 | dest[4 * x + 1] = source[x]; |
| 119 | dest[4 * x + 2] = source[x]; |
| 120 | dest[4 * x + 3] = 0xFF; |
| 121 | } |
| 122 | } |
| 123 | else // L8 destination format |
| 124 | { |
| 125 | memcpy(dest, source, width); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 130 | void Image::loadLuminanceFloatDataToRGBA(GLsizei width, GLsizei height, |
| 131 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 132 | { |
| 133 | const float *source = NULL; |
| 134 | float *dest = NULL; |
| 135 | |
| 136 | for (int y = 0; y < height; y++) |
| 137 | { |
| 138 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 139 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 140 | for (int x = 0; x < width; x++) |
| 141 | { |
| 142 | dest[4 * x + 0] = source[x]; |
| 143 | dest[4 * x + 1] = source[x]; |
| 144 | dest[4 * x + 2] = source[x]; |
| 145 | dest[4 * x + 3] = 1.0f; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
daniel@transgaming.com | 26041c9 | 2013-01-11 04:08:58 +0000 | [diff] [blame] | 150 | void Image::loadLuminanceFloatDataToRGB(GLsizei width, GLsizei height, |
| 151 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 152 | { |
| 153 | const float *source = NULL; |
| 154 | float *dest = NULL; |
| 155 | |
| 156 | for (int y = 0; y < height; y++) |
| 157 | { |
| 158 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 159 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 160 | for (int x = 0; x < width; x++) |
| 161 | { |
| 162 | dest[3 * x + 0] = source[x]; |
| 163 | dest[3 * x + 1] = source[x]; |
| 164 | dest[3 * x + 2] = source[x]; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 169 | void Image::loadLuminanceHalfFloatDataToRGBA(GLsizei width, GLsizei height, |
| 170 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 171 | { |
| 172 | const unsigned short *source = NULL; |
| 173 | unsigned short *dest = NULL; |
| 174 | |
| 175 | for (int y = 0; y < height; y++) |
| 176 | { |
| 177 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 178 | dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 179 | for (int x = 0; x < width; x++) |
| 180 | { |
| 181 | dest[4 * x + 0] = source[x]; |
| 182 | dest[4 * x + 1] = source[x]; |
| 183 | dest[4 * x + 2] = source[x]; |
| 184 | dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1 |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 189 | void Image::loadLuminanceAlphaDataToNativeOrBGRA(GLsizei width, GLsizei height, |
| 190 | int inputPitch, const void *input, size_t outputPitch, void *output, bool native) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 191 | { |
| 192 | const unsigned char *source = NULL; |
| 193 | unsigned char *dest = NULL; |
| 194 | |
| 195 | for (int y = 0; y < height; y++) |
| 196 | { |
| 197 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 198 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 199 | |
| 200 | if (!native) // BGRA8 destination format |
| 201 | { |
| 202 | for (int x = 0; x < width; x++) |
| 203 | { |
| 204 | dest[4 * x + 0] = source[2*x+0]; |
| 205 | dest[4 * x + 1] = source[2*x+0]; |
| 206 | dest[4 * x + 2] = source[2*x+0]; |
| 207 | dest[4 * x + 3] = source[2*x+1]; |
| 208 | } |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | memcpy(dest, source, width * 2); |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 217 | void Image::loadLuminanceAlphaFloatDataToRGBA(GLsizei width, GLsizei height, |
| 218 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 219 | { |
| 220 | const float *source = NULL; |
| 221 | float *dest = NULL; |
| 222 | |
| 223 | for (int y = 0; y < height; y++) |
| 224 | { |
| 225 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 226 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 227 | for (int x = 0; x < width; x++) |
| 228 | { |
| 229 | dest[4 * x + 0] = source[2*x+0]; |
| 230 | dest[4 * x + 1] = source[2*x+0]; |
| 231 | dest[4 * x + 2] = source[2*x+0]; |
| 232 | dest[4 * x + 3] = source[2*x+1]; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 237 | void Image::loadLuminanceAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, |
| 238 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 239 | { |
| 240 | const unsigned short *source = NULL; |
| 241 | unsigned short *dest = NULL; |
| 242 | |
| 243 | for (int y = 0; y < height; y++) |
| 244 | { |
| 245 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 246 | dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 247 | for (int x = 0; x < width; x++) |
| 248 | { |
| 249 | dest[4 * x + 0] = source[2*x+0]; |
| 250 | dest[4 * x + 1] = source[2*x+0]; |
| 251 | dest[4 * x + 2] = source[2*x+0]; |
| 252 | dest[4 * x + 3] = source[2*x+1]; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 257 | void Image::loadRGBUByteDataToBGRX(GLsizei width, GLsizei height, |
| 258 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 259 | { |
| 260 | const unsigned char *source = NULL; |
| 261 | unsigned char *dest = NULL; |
| 262 | |
| 263 | for (int y = 0; y < height; y++) |
| 264 | { |
| 265 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 266 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 267 | for (int x = 0; x < width; x++) |
| 268 | { |
| 269 | dest[4 * x + 0] = source[x * 3 + 2]; |
| 270 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 271 | dest[4 * x + 2] = source[x * 3 + 0]; |
| 272 | dest[4 * x + 3] = 0xFF; |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
daniel@transgaming.com | 005979d | 2012-12-20 21:11:29 +0000 | [diff] [blame] | 277 | void Image::loadRGBUByteDataToRGBA(GLsizei width, GLsizei height, |
| 278 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 279 | { |
| 280 | const unsigned char *source = NULL; |
| 281 | unsigned char *dest = NULL; |
| 282 | |
| 283 | for (int y = 0; y < height; y++) |
| 284 | { |
| 285 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 286 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 287 | for (int x = 0; x < width; x++) |
| 288 | { |
| 289 | dest[4 * x + 0] = source[x * 3 + 0]; |
| 290 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 291 | dest[4 * x + 2] = source[x * 3 + 2]; |
| 292 | dest[4 * x + 3] = 0xFF; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 297 | void Image::loadRGB565DataToBGRA(GLsizei width, GLsizei height, |
| 298 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 299 | { |
| 300 | const unsigned short *source = NULL; |
| 301 | unsigned char *dest = NULL; |
| 302 | |
| 303 | for (int y = 0; y < height; y++) |
| 304 | { |
| 305 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 306 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 307 | for (int x = 0; x < width; x++) |
| 308 | { |
| 309 | unsigned short rgba = source[x]; |
| 310 | dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2); |
| 311 | dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9); |
| 312 | dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 313 | dest[4 * x + 3] = 0xFF; |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
daniel@transgaming.com | 005979d | 2012-12-20 21:11:29 +0000 | [diff] [blame] | 318 | void Image::loadRGB565DataToRGBA(GLsizei width, GLsizei height, |
| 319 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 320 | { |
| 321 | const unsigned short *source = NULL; |
| 322 | unsigned char *dest = NULL; |
| 323 | |
| 324 | for (int y = 0; y < height; y++) |
| 325 | { |
| 326 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 327 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 328 | for (int x = 0; x < width; x++) |
| 329 | { |
| 330 | unsigned short rgba = source[x]; |
| 331 | dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 332 | dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9); |
| 333 | dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2); |
| 334 | dest[4 * x + 3] = 0xFF; |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 339 | void Image::loadRGBFloatDataToRGBA(GLsizei width, GLsizei height, |
| 340 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 341 | { |
| 342 | const float *source = NULL; |
| 343 | float *dest = NULL; |
| 344 | |
| 345 | for (int y = 0; y < height; y++) |
| 346 | { |
| 347 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 348 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 349 | 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] = 1.0f; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
daniel@transgaming.com | 005979d | 2012-12-20 21:11:29 +0000 | [diff] [blame] | 359 | void Image::loadRGBFloatDataToNative(GLsizei width, GLsizei height, |
| 360 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 361 | { |
| 362 | const float *source = NULL; |
| 363 | float *dest = NULL; |
| 364 | |
| 365 | for (int y = 0; y < height; y++) |
| 366 | { |
| 367 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 368 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 369 | memcpy(dest, source, width * 12); |
| 370 | } |
| 371 | } |
| 372 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 373 | void Image::loadRGBHalfFloatDataToRGBA(GLsizei width, GLsizei height, |
| 374 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 375 | { |
| 376 | const unsigned short *source = NULL; |
| 377 | unsigned short *dest = NULL; |
| 378 | |
| 379 | for (int y = 0; y < height; y++) |
| 380 | { |
| 381 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 382 | dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 383 | for (int x = 0; x < width; x++) |
| 384 | { |
| 385 | dest[4 * x + 0] = source[x * 3 + 0]; |
| 386 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 387 | dest[4 * x + 2] = source[x * 3 + 2]; |
| 388 | dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1 |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 393 | void Image::loadRGBAUByteDataToBGRA(GLsizei width, GLsizei height, |
| 394 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 395 | { |
| 396 | const unsigned int *source = NULL; |
| 397 | unsigned int *dest = NULL; |
| 398 | for (int y = 0; y < height; y++) |
| 399 | { |
| 400 | source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 401 | dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 402 | |
| 403 | for (int x = 0; x < width; x++) |
| 404 | { |
| 405 | unsigned int rgba = source[x]; |
| 406 | dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
daniel@transgaming.com | 005979d | 2012-12-20 21:11:29 +0000 | [diff] [blame] | 411 | void Image::loadRGBAUByteDataToNative(GLsizei width, GLsizei height, |
| 412 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 413 | { |
| 414 | const unsigned int *source = NULL; |
| 415 | unsigned int *dest = NULL; |
| 416 | for (int y = 0; y < height; y++) |
| 417 | { |
| 418 | source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 419 | dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 420 | |
| 421 | memcpy(dest, source, width * 4); |
| 422 | } |
| 423 | } |
| 424 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 425 | void Image::loadRGBA4444DataToBGRA(GLsizei width, GLsizei height, |
| 426 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 427 | { |
| 428 | const unsigned short *source = NULL; |
| 429 | unsigned char *dest = NULL; |
| 430 | |
| 431 | for (int y = 0; y < height; y++) |
| 432 | { |
| 433 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 434 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 435 | for (int x = 0; x < width; x++) |
| 436 | { |
| 437 | unsigned short rgba = source[x]; |
| 438 | dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); |
| 439 | dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); |
| 440 | dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); |
| 441 | dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
daniel@transgaming.com | 005979d | 2012-12-20 21:11:29 +0000 | [diff] [blame] | 446 | void Image::loadRGBA4444DataToRGBA(GLsizei width, GLsizei height, |
| 447 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 448 | { |
| 449 | const unsigned short *source = NULL; |
| 450 | unsigned char *dest = NULL; |
| 451 | |
| 452 | for (int y = 0; y < height; y++) |
| 453 | { |
| 454 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 455 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 456 | for (int x = 0; x < width; x++) |
| 457 | { |
| 458 | unsigned short rgba = source[x]; |
| 459 | dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); |
| 460 | dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); |
| 461 | dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); |
| 462 | dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 467 | void Image::loadRGBA5551DataToBGRA(GLsizei width, GLsizei height, |
| 468 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 469 | { |
| 470 | const unsigned short *source = NULL; |
| 471 | unsigned char *dest = NULL; |
| 472 | |
| 473 | for (int y = 0; y < height; y++) |
| 474 | { |
| 475 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 476 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 477 | for (int x = 0; x < width; x++) |
| 478 | { |
| 479 | unsigned short rgba = source[x]; |
| 480 | dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); |
| 481 | dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); |
| 482 | dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 483 | dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
daniel@transgaming.com | 005979d | 2012-12-20 21:11:29 +0000 | [diff] [blame] | 488 | void Image::loadRGBA5551DataToRGBA(GLsizei width, GLsizei height, |
| 489 | int inputPitch, const void *input, size_t outputPitch, void *output) |
| 490 | { |
| 491 | const unsigned short *source = NULL; |
| 492 | unsigned char *dest = NULL; |
| 493 | |
| 494 | for (int y = 0; y < height; y++) |
| 495 | { |
| 496 | source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 497 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 498 | for (int x = 0; x < width; x++) |
| 499 | { |
| 500 | unsigned short rgba = source[x]; |
| 501 | dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 502 | dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); |
| 503 | dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); |
| 504 | dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 509 | void Image::loadRGBAFloatDataToRGBA(GLsizei width, GLsizei height, |
| 510 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 511 | { |
| 512 | const float *source = NULL; |
| 513 | float *dest = NULL; |
| 514 | |
| 515 | for (int y = 0; y < height; y++) |
| 516 | { |
| 517 | source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); |
| 518 | dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); |
| 519 | memcpy(dest, source, width * 16); |
| 520 | } |
| 521 | } |
| 522 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 523 | void Image::loadRGBAHalfFloatDataToRGBA(GLsizei width, GLsizei height, |
| 524 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 525 | { |
| 526 | const unsigned char *source = NULL; |
| 527 | unsigned char *dest = NULL; |
| 528 | |
| 529 | for (int y = 0; y < height; y++) |
| 530 | { |
| 531 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 532 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 533 | memcpy(dest, source, width * 8); |
| 534 | } |
| 535 | } |
| 536 | |
daniel@transgaming.com | 8ca7d37 | 2012-12-20 21:11:22 +0000 | [diff] [blame] | 537 | void Image::loadBGRADataToBGRA(GLsizei width, GLsizei height, |
| 538 | int inputPitch, const void *input, size_t outputPitch, void *output) |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 539 | { |
| 540 | const unsigned char *source = NULL; |
| 541 | unsigned char *dest = NULL; |
| 542 | |
| 543 | for (int y = 0; y < height; y++) |
| 544 | { |
| 545 | source = static_cast<const unsigned char*>(input) + y * inputPitch; |
| 546 | dest = static_cast<unsigned char*>(output) + y * outputPitch; |
| 547 | memcpy(dest, source, width*4); |
| 548 | } |
| 549 | } |
| 550 | |
daniel@transgaming.com | b9d7e6f | 2012-10-31 19:08:32 +0000 | [diff] [blame] | 551 | } |