1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/libGLESv2/renderer/Image.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,548 @@ 1.4 +#include "precompiled.h" 1.5 +// 1.6 +// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. 1.7 +// Use of this source code is governed by a BSD-style license that can be 1.8 +// found in the LICENSE file. 1.9 +// 1.10 + 1.11 +// Image.h: Implements the rx::Image class, an abstract base class for the 1.12 +// renderer-specific classes which will define the interface to the underlying 1.13 +// surfaces or resources. 1.14 + 1.15 +#include "libGLESv2/renderer/Image.h" 1.16 + 1.17 +namespace rx 1.18 +{ 1.19 + 1.20 +Image::Image() 1.21 +{ 1.22 + mWidth = 0; 1.23 + mHeight = 0; 1.24 + mInternalFormat = GL_NONE; 1.25 + mActualFormat = GL_NONE; 1.26 +} 1.27 + 1.28 +void Image::loadAlphaDataToBGRA(GLsizei width, GLsizei height, 1.29 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.30 +{ 1.31 + const unsigned char *source = NULL; 1.32 + unsigned char *dest = NULL; 1.33 + 1.34 + for (int y = 0; y < height; y++) 1.35 + { 1.36 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.37 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.38 + for (int x = 0; x < width; x++) 1.39 + { 1.40 + dest[4 * x + 0] = 0; 1.41 + dest[4 * x + 1] = 0; 1.42 + dest[4 * x + 2] = 0; 1.43 + dest[4 * x + 3] = source[x]; 1.44 + } 1.45 + } 1.46 +} 1.47 + 1.48 +void Image::loadAlphaDataToNative(GLsizei width, GLsizei height, 1.49 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.50 +{ 1.51 + const unsigned char *source = NULL; 1.52 + unsigned char *dest = NULL; 1.53 + 1.54 + for (int y = 0; y < height; y++) 1.55 + { 1.56 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.57 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.58 + memcpy(dest, source, width); 1.59 + } 1.60 +} 1.61 + 1.62 +void Image::loadAlphaFloatDataToRGBA(GLsizei width, GLsizei height, 1.63 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.64 +{ 1.65 + const float *source = NULL; 1.66 + float *dest = NULL; 1.67 + 1.68 + for (int y = 0; y < height; y++) 1.69 + { 1.70 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.71 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.72 + for (int x = 0; x < width; x++) 1.73 + { 1.74 + dest[4 * x + 0] = 0; 1.75 + dest[4 * x + 1] = 0; 1.76 + dest[4 * x + 2] = 0; 1.77 + dest[4 * x + 3] = source[x]; 1.78 + } 1.79 + } 1.80 +} 1.81 + 1.82 +void Image::loadAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, 1.83 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.84 +{ 1.85 + const unsigned short *source = NULL; 1.86 + unsigned short *dest = NULL; 1.87 + 1.88 + for (int y = 0; y < height; y++) 1.89 + { 1.90 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.91 + dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.92 + for (int x = 0; x < width; x++) 1.93 + { 1.94 + dest[4 * x + 0] = 0; 1.95 + dest[4 * x + 1] = 0; 1.96 + dest[4 * x + 2] = 0; 1.97 + dest[4 * x + 3] = source[x]; 1.98 + } 1.99 + } 1.100 +} 1.101 + 1.102 +void Image::loadLuminanceDataToNativeOrBGRA(GLsizei width, GLsizei height, 1.103 + int inputPitch, const void *input, size_t outputPitch, void *output, bool native) 1.104 +{ 1.105 + const unsigned char *source = NULL; 1.106 + unsigned char *dest = NULL; 1.107 + 1.108 + for (int y = 0; y < height; y++) 1.109 + { 1.110 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.111 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.112 + 1.113 + if (!native) // BGRA8 destination format 1.114 + { 1.115 + for (int x = 0; x < width; x++) 1.116 + { 1.117 + dest[4 * x + 0] = source[x]; 1.118 + dest[4 * x + 1] = source[x]; 1.119 + dest[4 * x + 2] = source[x]; 1.120 + dest[4 * x + 3] = 0xFF; 1.121 + } 1.122 + } 1.123 + else // L8 destination format 1.124 + { 1.125 + memcpy(dest, source, width); 1.126 + } 1.127 + } 1.128 +} 1.129 + 1.130 +void Image::loadLuminanceFloatDataToRGBA(GLsizei width, GLsizei height, 1.131 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.132 +{ 1.133 + const float *source = NULL; 1.134 + float *dest = NULL; 1.135 + 1.136 + for (int y = 0; y < height; y++) 1.137 + { 1.138 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.139 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.140 + for (int x = 0; x < width; x++) 1.141 + { 1.142 + dest[4 * x + 0] = source[x]; 1.143 + dest[4 * x + 1] = source[x]; 1.144 + dest[4 * x + 2] = source[x]; 1.145 + dest[4 * x + 3] = 1.0f; 1.146 + } 1.147 + } 1.148 +} 1.149 + 1.150 +void Image::loadLuminanceFloatDataToRGB(GLsizei width, GLsizei height, 1.151 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.152 +{ 1.153 + const float *source = NULL; 1.154 + float *dest = NULL; 1.155 + 1.156 + for (int y = 0; y < height; y++) 1.157 + { 1.158 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.159 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.160 + for (int x = 0; x < width; x++) 1.161 + { 1.162 + dest[3 * x + 0] = source[x]; 1.163 + dest[3 * x + 1] = source[x]; 1.164 + dest[3 * x + 2] = source[x]; 1.165 + } 1.166 + } 1.167 +} 1.168 + 1.169 +void Image::loadLuminanceHalfFloatDataToRGBA(GLsizei width, GLsizei height, 1.170 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.171 +{ 1.172 + const unsigned short *source = NULL; 1.173 + unsigned short *dest = NULL; 1.174 + 1.175 + for (int y = 0; y < height; y++) 1.176 + { 1.177 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.178 + dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.179 + for (int x = 0; x < width; x++) 1.180 + { 1.181 + dest[4 * x + 0] = source[x]; 1.182 + dest[4 * x + 1] = source[x]; 1.183 + dest[4 * x + 2] = source[x]; 1.184 + dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1 1.185 + } 1.186 + } 1.187 +} 1.188 + 1.189 +void Image::loadLuminanceAlphaDataToNativeOrBGRA(GLsizei width, GLsizei height, 1.190 + int inputPitch, const void *input, size_t outputPitch, void *output, bool native) 1.191 +{ 1.192 + const unsigned char *source = NULL; 1.193 + unsigned char *dest = NULL; 1.194 + 1.195 + for (int y = 0; y < height; y++) 1.196 + { 1.197 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.198 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.199 + 1.200 + if (!native) // BGRA8 destination format 1.201 + { 1.202 + for (int x = 0; x < width; x++) 1.203 + { 1.204 + dest[4 * x + 0] = source[2*x+0]; 1.205 + dest[4 * x + 1] = source[2*x+0]; 1.206 + dest[4 * x + 2] = source[2*x+0]; 1.207 + dest[4 * x + 3] = source[2*x+1]; 1.208 + } 1.209 + } 1.210 + else 1.211 + { 1.212 + memcpy(dest, source, width * 2); 1.213 + } 1.214 + } 1.215 +} 1.216 + 1.217 +void Image::loadLuminanceAlphaFloatDataToRGBA(GLsizei width, GLsizei height, 1.218 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.219 +{ 1.220 + const float *source = NULL; 1.221 + float *dest = NULL; 1.222 + 1.223 + for (int y = 0; y < height; y++) 1.224 + { 1.225 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.226 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.227 + for (int x = 0; x < width; x++) 1.228 + { 1.229 + dest[4 * x + 0] = source[2*x+0]; 1.230 + dest[4 * x + 1] = source[2*x+0]; 1.231 + dest[4 * x + 2] = source[2*x+0]; 1.232 + dest[4 * x + 3] = source[2*x+1]; 1.233 + } 1.234 + } 1.235 +} 1.236 + 1.237 +void Image::loadLuminanceAlphaHalfFloatDataToRGBA(GLsizei width, GLsizei height, 1.238 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.239 +{ 1.240 + const unsigned short *source = NULL; 1.241 + unsigned short *dest = NULL; 1.242 + 1.243 + for (int y = 0; y < height; y++) 1.244 + { 1.245 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.246 + dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.247 + for (int x = 0; x < width; x++) 1.248 + { 1.249 + dest[4 * x + 0] = source[2*x+0]; 1.250 + dest[4 * x + 1] = source[2*x+0]; 1.251 + dest[4 * x + 2] = source[2*x+0]; 1.252 + dest[4 * x + 3] = source[2*x+1]; 1.253 + } 1.254 + } 1.255 +} 1.256 + 1.257 +void Image::loadRGBUByteDataToBGRX(GLsizei width, GLsizei height, 1.258 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.259 +{ 1.260 + const unsigned char *source = NULL; 1.261 + unsigned char *dest = NULL; 1.262 + 1.263 + for (int y = 0; y < height; y++) 1.264 + { 1.265 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.266 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.267 + for (int x = 0; x < width; x++) 1.268 + { 1.269 + dest[4 * x + 0] = source[x * 3 + 2]; 1.270 + dest[4 * x + 1] = source[x * 3 + 1]; 1.271 + dest[4 * x + 2] = source[x * 3 + 0]; 1.272 + dest[4 * x + 3] = 0xFF; 1.273 + } 1.274 + } 1.275 +} 1.276 + 1.277 +void Image::loadRGBUByteDataToRGBA(GLsizei width, GLsizei height, 1.278 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.279 +{ 1.280 + const unsigned char *source = NULL; 1.281 + unsigned char *dest = NULL; 1.282 + 1.283 + for (int y = 0; y < height; y++) 1.284 + { 1.285 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.286 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.287 + for (int x = 0; x < width; x++) 1.288 + { 1.289 + dest[4 * x + 0] = source[x * 3 + 0]; 1.290 + dest[4 * x + 1] = source[x * 3 + 1]; 1.291 + dest[4 * x + 2] = source[x * 3 + 2]; 1.292 + dest[4 * x + 3] = 0xFF; 1.293 + } 1.294 + } 1.295 +} 1.296 + 1.297 +void Image::loadRGB565DataToBGRA(GLsizei width, GLsizei height, 1.298 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.299 +{ 1.300 + const unsigned short *source = NULL; 1.301 + unsigned char *dest = NULL; 1.302 + 1.303 + for (int y = 0; y < height; y++) 1.304 + { 1.305 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.306 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.307 + for (int x = 0; x < width; x++) 1.308 + { 1.309 + unsigned short rgba = source[x]; 1.310 + dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2); 1.311 + dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9); 1.312 + dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); 1.313 + dest[4 * x + 3] = 0xFF; 1.314 + } 1.315 + } 1.316 +} 1.317 + 1.318 +void Image::loadRGB565DataToRGBA(GLsizei width, GLsizei height, 1.319 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.320 +{ 1.321 + const unsigned short *source = NULL; 1.322 + unsigned char *dest = NULL; 1.323 + 1.324 + for (int y = 0; y < height; y++) 1.325 + { 1.326 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.327 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.328 + for (int x = 0; x < width; x++) 1.329 + { 1.330 + unsigned short rgba = source[x]; 1.331 + dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); 1.332 + dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9); 1.333 + dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2); 1.334 + dest[4 * x + 3] = 0xFF; 1.335 + } 1.336 + } 1.337 +} 1.338 + 1.339 +void Image::loadRGBFloatDataToRGBA(GLsizei width, GLsizei height, 1.340 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.341 +{ 1.342 + const float *source = NULL; 1.343 + float *dest = NULL; 1.344 + 1.345 + for (int y = 0; y < height; y++) 1.346 + { 1.347 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.348 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.349 + for (int x = 0; x < width; x++) 1.350 + { 1.351 + dest[4 * x + 0] = source[x * 3 + 0]; 1.352 + dest[4 * x + 1] = source[x * 3 + 1]; 1.353 + dest[4 * x + 2] = source[x * 3 + 2]; 1.354 + dest[4 * x + 3] = 1.0f; 1.355 + } 1.356 + } 1.357 +} 1.358 + 1.359 +void Image::loadRGBFloatDataToNative(GLsizei width, GLsizei height, 1.360 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.361 +{ 1.362 + const float *source = NULL; 1.363 + float *dest = NULL; 1.364 + 1.365 + for (int y = 0; y < height; y++) 1.366 + { 1.367 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.368 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.369 + memcpy(dest, source, width * 12); 1.370 + } 1.371 +} 1.372 + 1.373 +void Image::loadRGBHalfFloatDataToRGBA(GLsizei width, GLsizei height, 1.374 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.375 +{ 1.376 + const unsigned short *source = NULL; 1.377 + unsigned short *dest = NULL; 1.378 + 1.379 + for (int y = 0; y < height; y++) 1.380 + { 1.381 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.382 + dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.383 + for (int x = 0; x < width; x++) 1.384 + { 1.385 + dest[4 * x + 0] = source[x * 3 + 0]; 1.386 + dest[4 * x + 1] = source[x * 3 + 1]; 1.387 + dest[4 * x + 2] = source[x * 3 + 2]; 1.388 + dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1 1.389 + } 1.390 + } 1.391 +} 1.392 + 1.393 +void Image::loadRGBAUByteDataToBGRA(GLsizei width, GLsizei height, 1.394 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.395 +{ 1.396 + const unsigned int *source = NULL; 1.397 + unsigned int *dest = NULL; 1.398 + for (int y = 0; y < height; y++) 1.399 + { 1.400 + source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.401 + dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.402 + 1.403 + for (int x = 0; x < width; x++) 1.404 + { 1.405 + unsigned int rgba = source[x]; 1.406 + dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00); 1.407 + } 1.408 + } 1.409 +} 1.410 + 1.411 +void Image::loadRGBAUByteDataToNative(GLsizei width, GLsizei height, 1.412 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.413 +{ 1.414 + const unsigned int *source = NULL; 1.415 + unsigned int *dest = NULL; 1.416 + for (int y = 0; y < height; y++) 1.417 + { 1.418 + source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.419 + dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.420 + 1.421 + memcpy(dest, source, width * 4); 1.422 + } 1.423 +} 1.424 + 1.425 +void Image::loadRGBA4444DataToBGRA(GLsizei width, GLsizei height, 1.426 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.427 +{ 1.428 + const unsigned short *source = NULL; 1.429 + unsigned char *dest = NULL; 1.430 + 1.431 + for (int y = 0; y < height; y++) 1.432 + { 1.433 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.434 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.435 + for (int x = 0; x < width; x++) 1.436 + { 1.437 + unsigned short rgba = source[x]; 1.438 + dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); 1.439 + dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); 1.440 + dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); 1.441 + dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); 1.442 + } 1.443 + } 1.444 +} 1.445 + 1.446 +void Image::loadRGBA4444DataToRGBA(GLsizei width, GLsizei height, 1.447 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.448 +{ 1.449 + const unsigned short *source = NULL; 1.450 + unsigned char *dest = NULL; 1.451 + 1.452 + for (int y = 0; y < height; y++) 1.453 + { 1.454 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.455 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.456 + for (int x = 0; x < width; x++) 1.457 + { 1.458 + unsigned short rgba = source[x]; 1.459 + dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); 1.460 + dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); 1.461 + dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); 1.462 + dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); 1.463 + } 1.464 + } 1.465 +} 1.466 + 1.467 +void Image::loadRGBA5551DataToBGRA(GLsizei width, GLsizei height, 1.468 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.469 +{ 1.470 + const unsigned short *source = NULL; 1.471 + unsigned char *dest = NULL; 1.472 + 1.473 + for (int y = 0; y < height; y++) 1.474 + { 1.475 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.476 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.477 + for (int x = 0; x < width; x++) 1.478 + { 1.479 + unsigned short rgba = source[x]; 1.480 + dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); 1.481 + dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); 1.482 + dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); 1.483 + dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; 1.484 + } 1.485 + } 1.486 +} 1.487 + 1.488 +void Image::loadRGBA5551DataToRGBA(GLsizei width, GLsizei height, 1.489 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.490 +{ 1.491 + const unsigned short *source = NULL; 1.492 + unsigned char *dest = NULL; 1.493 + 1.494 + for (int y = 0; y < height; y++) 1.495 + { 1.496 + source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.497 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.498 + for (int x = 0; x < width; x++) 1.499 + { 1.500 + unsigned short rgba = source[x]; 1.501 + dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); 1.502 + dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); 1.503 + dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); 1.504 + dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; 1.505 + } 1.506 + } 1.507 +} 1.508 + 1.509 +void Image::loadRGBAFloatDataToRGBA(GLsizei width, GLsizei height, 1.510 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.511 +{ 1.512 + const float *source = NULL; 1.513 + float *dest = NULL; 1.514 + 1.515 + for (int y = 0; y < height; y++) 1.516 + { 1.517 + source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch); 1.518 + dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch); 1.519 + memcpy(dest, source, width * 16); 1.520 + } 1.521 +} 1.522 + 1.523 +void Image::loadRGBAHalfFloatDataToRGBA(GLsizei width, GLsizei height, 1.524 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.525 +{ 1.526 + const unsigned char *source = NULL; 1.527 + unsigned char *dest = NULL; 1.528 + 1.529 + for (int y = 0; y < height; y++) 1.530 + { 1.531 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.532 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.533 + memcpy(dest, source, width * 8); 1.534 + } 1.535 +} 1.536 + 1.537 +void Image::loadBGRADataToBGRA(GLsizei width, GLsizei height, 1.538 + int inputPitch, const void *input, size_t outputPitch, void *output) 1.539 +{ 1.540 + const unsigned char *source = NULL; 1.541 + unsigned char *dest = NULL; 1.542 + 1.543 + for (int y = 0; y < height; y++) 1.544 + { 1.545 + source = static_cast<const unsigned char*>(input) + y * inputPitch; 1.546 + dest = static_cast<unsigned char*>(output) + y * outputPitch; 1.547 + memcpy(dest, source, width*4); 1.548 + } 1.549 +} 1.550 + 1.551 +}