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