shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
| 2 | // |
| 3 | // Copyright (c) 0013 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 | |
| 8 | // loadimage.cpp: Defines image loading functions. |
| 9 | |
| 10 | #include "libGLESv2/renderer/loadimage.h" |
| 11 | |
| 12 | namespace rx |
| 13 | { |
| 14 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 15 | void loadAlphaDataToBGRA(int width, int height, int depth, |
| 16 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 17 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 18 | { |
| 19 | const unsigned char *source = NULL; |
| 20 | unsigned char *dest = NULL; |
| 21 | |
| 22 | for (int z = 0; z < depth; z++) |
| 23 | { |
| 24 | for (int y = 0; y < height; y++) |
| 25 | { |
| 26 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 27 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 28 | for (int x = 0; x < width; x++) |
| 29 | { |
| 30 | dest[4 * x + 0] = 0; |
| 31 | dest[4 * x + 1] = 0; |
| 32 | dest[4 * x + 2] = 0; |
| 33 | dest[4 * x + 3] = source[x]; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void loadAlphaDataToNative(int width, int height, int depth, |
| 40 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 41 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 42 | { |
| 43 | const unsigned char *source = NULL; |
| 44 | unsigned char *dest = NULL; |
| 45 | |
| 46 | for (int z = 0; z < depth; z++) |
| 47 | { |
| 48 | for (int y = 0; y < height; y++) |
| 49 | { |
| 50 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 51 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 52 | memcpy(dest, source, width); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void loadAlphaFloatDataToRGBA(int width, int height, int depth, |
| 58 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 59 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 60 | { |
| 61 | const float *source = NULL; |
| 62 | float *dest = NULL; |
| 63 | |
| 64 | for (int z = 0; z < depth; z++) |
| 65 | { |
| 66 | for (int y = 0; y < height; y++) |
| 67 | { |
| 68 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 69 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 70 | for (int x = 0; x < width; x++) |
| 71 | { |
| 72 | dest[4 * x + 0] = 0; |
| 73 | dest[4 * x + 1] = 0; |
| 74 | dest[4 * x + 2] = 0; |
| 75 | dest[4 * x + 3] = source[x]; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void loadAlphaHalfFloatDataToRGBA(int width, int height, int depth, |
| 82 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 83 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 84 | { |
| 85 | const unsigned short *source = NULL; |
| 86 | unsigned short *dest = NULL; |
| 87 | |
| 88 | for (int z = 0; z < depth; z++) |
| 89 | { |
| 90 | for (int y = 0; y < height; y++) |
| 91 | { |
| 92 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 93 | dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch); |
| 94 | for (int x = 0; x < width; x++) |
| 95 | { |
| 96 | dest[4 * x + 0] = 0; |
| 97 | dest[4 * x + 1] = 0; |
| 98 | dest[4 * x + 2] = 0; |
| 99 | dest[4 * x + 3] = source[x]; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void loadLuminanceDataToNative(int width, int height, int depth, |
| 106 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 107 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 108 | { |
| 109 | const unsigned char *source = NULL; |
| 110 | unsigned char *dest = NULL; |
| 111 | |
| 112 | for (int z = 0; z < depth; z++) |
| 113 | { |
| 114 | for (int y = 0; y < height; y++) |
| 115 | { |
| 116 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 117 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 118 | memcpy(dest, source, width); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void loadLuminanceDataToBGRA(int width, int height, int depth, |
| 124 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 125 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 126 | { |
| 127 | const unsigned char *source = NULL; |
| 128 | unsigned char *dest = NULL; |
| 129 | |
| 130 | for (int z = 0; z < depth; z++) |
| 131 | { |
| 132 | for (int y = 0; y < height; y++) |
| 133 | { |
| 134 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 135 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 136 | for (int x = 0; x < width; x++) |
| 137 | { |
| 138 | dest[4 * x + 0] = source[x]; |
| 139 | dest[4 * x + 1] = source[x]; |
| 140 | dest[4 * x + 2] = source[x]; |
| 141 | dest[4 * x + 3] = 0xFF; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void loadLuminanceFloatDataToRGBA(int width, int height, int depth, |
| 148 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 149 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 150 | { |
| 151 | const float *source = NULL; |
| 152 | float *dest = NULL; |
| 153 | |
| 154 | for (int z = 0; z < depth; z++) |
| 155 | { |
| 156 | for (int y = 0; y < height; y++) |
| 157 | { |
| 158 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 159 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 160 | for (int x = 0; x < width; x++) |
| 161 | { |
| 162 | dest[4 * x + 0] = source[x]; |
| 163 | dest[4 * x + 1] = source[x]; |
| 164 | dest[4 * x + 2] = source[x]; |
| 165 | dest[4 * x + 3] = 1.0f; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void loadLuminanceFloatDataToRGB(int width, int height, int depth, |
| 172 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 173 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 174 | { |
| 175 | const float *source = NULL; |
| 176 | float *dest = NULL; |
| 177 | |
| 178 | for (int z = 0; z < depth; z++) |
| 179 | { |
| 180 | for (int y = 0; y < height; y++) |
| 181 | { |
| 182 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 183 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 184 | for (int x = 0; x < width; x++) |
| 185 | { |
| 186 | dest[3 * x + 0] = source[x]; |
| 187 | dest[3 * x + 1] = source[x]; |
| 188 | dest[3 * x + 2] = source[x]; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void loadLuminanceHalfFloatDataToRGBA(int width, int height, int depth, |
| 195 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 196 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 197 | { |
| 198 | const unsigned short *source = NULL; |
| 199 | unsigned short *dest = NULL; |
| 200 | |
| 201 | for (int z = 0; z < depth; z++) |
| 202 | { |
| 203 | for (int y = 0; y < height; y++) |
| 204 | { |
| 205 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 206 | dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch); |
| 207 | for (int x = 0; x < width; x++) |
| 208 | { |
| 209 | dest[4 * x + 0] = source[x]; |
| 210 | dest[4 * x + 1] = source[x]; |
| 211 | dest[4 * x + 2] = source[x]; |
| 212 | dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1 |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | void loadLuminanceAlphaDataToNative(int width, int height, int depth, |
| 219 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 220 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 221 | { |
| 222 | const unsigned char *source = NULL; |
| 223 | unsigned char *dest = NULL; |
| 224 | |
| 225 | for (int z = 0; z < depth; z++) |
| 226 | { |
| 227 | for (int y = 0; y < height; y++) |
| 228 | { |
| 229 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 230 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 231 | |
| 232 | memcpy(dest, source, width * 2); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | void loadLuminanceAlphaDataToBGRA(int width, int height, int depth, |
| 238 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 239 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 240 | { |
| 241 | const unsigned char *source = NULL; |
| 242 | unsigned char *dest = NULL; |
| 243 | |
| 244 | for (int z = 0; z < depth; z++) |
| 245 | { |
| 246 | for (int y = 0; y < height; y++) |
| 247 | { |
| 248 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 249 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 250 | |
| 251 | for (int x = 0; x < width; x++) |
| 252 | { |
| 253 | dest[4 * x + 0] = source[2*x+0]; |
| 254 | dest[4 * x + 1] = source[2*x+0]; |
| 255 | dest[4 * x + 2] = source[2*x+0]; |
| 256 | dest[4 * x + 3] = source[2*x+1]; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | void loadLuminanceAlphaFloatDataToRGBA(int width, int height, int depth, |
| 263 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 264 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 265 | { |
| 266 | const float *source = NULL; |
| 267 | float *dest = NULL; |
| 268 | |
| 269 | for (int z = 0; z < depth; z++) |
| 270 | { |
| 271 | for (int y = 0; y < height; y++) |
| 272 | { |
| 273 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 274 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 275 | for (int x = 0; x < width; x++) |
| 276 | { |
| 277 | dest[4 * x + 0] = source[2*x+0]; |
| 278 | dest[4 * x + 1] = source[2*x+0]; |
| 279 | dest[4 * x + 2] = source[2*x+0]; |
| 280 | dest[4 * x + 3] = source[2*x+1]; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void loadLuminanceAlphaHalfFloatDataToRGBA(int width, int height, int depth, |
| 287 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 288 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 289 | { |
| 290 | const unsigned short *source = NULL; |
| 291 | unsigned short *dest = NULL; |
| 292 | |
| 293 | for (int z = 0; z < depth; z++) |
| 294 | { |
| 295 | for (int y = 0; y < height; y++) |
| 296 | { |
| 297 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 298 | dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch); |
| 299 | for (int x = 0; x < width; x++) |
| 300 | { |
| 301 | dest[4 * x + 0] = source[2*x+0]; |
| 302 | dest[4 * x + 1] = source[2*x+0]; |
| 303 | dest[4 * x + 2] = source[2*x+0]; |
| 304 | dest[4 * x + 3] = source[2*x+1]; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | void loadRGBUByteDataToBGRX(int width, int height, int depth, |
| 311 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 312 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 313 | { |
| 314 | const unsigned char *source = NULL; |
| 315 | unsigned char *dest = NULL; |
| 316 | |
| 317 | for (int z = 0; z < depth; z++) |
| 318 | { |
| 319 | for (int y = 0; y < height; y++) |
| 320 | { |
| 321 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 322 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 323 | for (int x = 0; x < width; x++) |
| 324 | { |
| 325 | dest[4 * x + 0] = source[x * 3 + 2]; |
| 326 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 327 | dest[4 * x + 2] = source[x * 3 + 0]; |
| 328 | dest[4 * x + 3] = 0xFF; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void loadRGBUByteDataToRGBA(int width, int height, int depth, |
| 335 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 336 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 337 | { |
| 338 | const unsigned char *source = NULL; |
| 339 | unsigned char *dest = NULL; |
| 340 | |
| 341 | for (int z = 0; z < depth; z++) |
| 342 | { |
| 343 | for (int y = 0; y < height; y++) |
| 344 | { |
| 345 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 346 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 347 | for (int x = 0; x < width; x++) |
| 348 | { |
| 349 | dest[4 * x + 0] = source[x * 3 + 0]; |
| 350 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 351 | dest[4 * x + 2] = source[x * 3 + 2]; |
| 352 | dest[4 * x + 3] = 0xFF; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
shannonwoods@chromium.org | 36d0be9 | 2013-05-30 00:15:59 +0000 | [diff] [blame^] | 358 | void loadRGBSByteDataToRGBA(int width, int height, int depth, |
| 359 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 360 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 361 | { |
| 362 | const char *source = NULL; |
| 363 | char *dest = NULL; |
| 364 | |
| 365 | for (int z = 0; z < depth; z++) |
| 366 | { |
| 367 | for (int y = 0; y < height; y++) |
| 368 | { |
| 369 | source = offsetDataPointer<char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 370 | dest = offsetDataPointer<char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 371 | for (int x = 0; x < width; x++) |
| 372 | { |
| 373 | dest[4 * x + 0] = source[x * 3 + 0]; |
| 374 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 375 | dest[4 * x + 2] = source[x * 3 + 2]; |
| 376 | dest[4 * x + 3] = 0x7F; |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 382 | void loadRGB565DataToBGRA(int width, int height, int depth, |
| 383 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 384 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 385 | { |
| 386 | const unsigned short *source = NULL; |
| 387 | unsigned char *dest = NULL; |
| 388 | |
| 389 | for (int z = 0; z < depth; z++) |
| 390 | { |
| 391 | for (int y = 0; y < height; y++) |
| 392 | { |
| 393 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 394 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 395 | for (int x = 0; x < width; x++) |
| 396 | { |
| 397 | unsigned short rgba = source[x]; |
| 398 | dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2); |
| 399 | dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9); |
| 400 | dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 401 | dest[4 * x + 3] = 0xFF; |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | void loadRGB565DataToRGBA(int width, int height, int depth, |
| 408 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 409 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 410 | { |
| 411 | const unsigned short *source = NULL; |
| 412 | unsigned char *dest = NULL; |
| 413 | |
| 414 | for (int z = 0; z < depth; z++) |
| 415 | { |
| 416 | for (int y = 0; y < height; y++) |
| 417 | { |
| 418 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 419 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 420 | for (int x = 0; x < width; x++) |
| 421 | { |
| 422 | unsigned short rgba = source[x]; |
| 423 | dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 424 | dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9); |
| 425 | dest[4 * x + 2] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2); |
| 426 | dest[4 * x + 3] = 0xFF; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | void loadRGBFloatDataToRGBA(int width, int height, int depth, |
| 433 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 434 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 435 | { |
| 436 | const float *source = NULL; |
| 437 | float *dest = NULL; |
| 438 | |
| 439 | for (int z = 0; z < depth; z++) |
| 440 | { |
| 441 | for (int y = 0; y < height; y++) |
| 442 | { |
| 443 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 444 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 445 | for (int x = 0; x < width; x++) |
| 446 | { |
| 447 | dest[4 * x + 0] = source[x * 3 + 0]; |
| 448 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 449 | dest[4 * x + 2] = source[x * 3 + 2]; |
| 450 | dest[4 * x + 3] = 1.0f; |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | void loadRGBFloatDataToNative(int width, int height, int depth, |
| 457 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 458 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 459 | { |
| 460 | const float *source = NULL; |
| 461 | float *dest = NULL; |
| 462 | |
| 463 | for (int z = 0; z < depth; z++) |
| 464 | { |
| 465 | for (int y = 0; y < height; y++) |
| 466 | { |
| 467 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 468 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 469 | memcpy(dest, source, width * 12); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void loadRGBHalfFloatDataToRGBA(int width, int height, int depth, |
| 475 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 476 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 477 | { |
| 478 | const unsigned short *source = NULL; |
| 479 | unsigned short *dest = NULL; |
| 480 | |
| 481 | for (int z = 0; z < depth; z++) |
| 482 | { |
| 483 | for (int y = 0; y < height; y++) |
| 484 | { |
| 485 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 486 | dest = offsetDataPointer<unsigned short>(output, y, z, outputRowPitch, outputDepthPitch); |
| 487 | for (int x = 0; x < width; x++) |
| 488 | { |
| 489 | dest[4 * x + 0] = source[x * 3 + 0]; |
| 490 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 491 | dest[4 * x + 2] = source[x * 3 + 2]; |
| 492 | dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1 |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | void loadRGBAUByteDataToBGRA(int width, int height, int depth, |
| 499 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 500 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 501 | { |
| 502 | const unsigned int *source = NULL; |
| 503 | unsigned int *dest = NULL; |
| 504 | |
| 505 | for (int z = 0; z < depth; z++) |
| 506 | { |
| 507 | for (int y = 0; y < height; y++) |
| 508 | { |
| 509 | source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch); |
| 510 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 511 | |
| 512 | for (int x = 0; x < width; x++) |
| 513 | { |
| 514 | unsigned int rgba = source[x]; |
| 515 | dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | void loadRGBAUByteDataToNative(int width, int height, int depth, |
| 522 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 523 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 524 | { |
| 525 | const unsigned int *source = NULL; |
| 526 | unsigned int *dest = NULL; |
| 527 | |
| 528 | for (int z = 0; z < depth; z++) |
| 529 | { |
| 530 | for (int y = 0; y < height; y++) |
| 531 | { |
| 532 | source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch); |
| 533 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 534 | |
| 535 | memcpy(dest, source, width * 4); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | void loadRGBA4444DataToBGRA(int width, int height, int depth, |
| 541 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 542 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 543 | { |
| 544 | const unsigned short *source = NULL; |
| 545 | unsigned char *dest = NULL; |
| 546 | |
| 547 | for (int z = 0; z < depth; z++) |
| 548 | { |
| 549 | for (int y = 0; y < height; y++) |
| 550 | { |
| 551 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 552 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 553 | for (int x = 0; x < width; x++) |
| 554 | { |
| 555 | unsigned short rgba = source[x]; |
| 556 | dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); |
| 557 | dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); |
| 558 | dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); |
| 559 | dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | void loadRGBA4444DataToRGBA(int width, int height, int depth, |
| 566 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 567 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 568 | { |
| 569 | const unsigned short *source = NULL; |
| 570 | unsigned char *dest = NULL; |
| 571 | |
| 572 | for (int z = 0; z < depth; z++) |
| 573 | { |
| 574 | for (int y = 0; y < height; y++) |
| 575 | { |
| 576 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 577 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 578 | for (int x = 0; x < width; x++) |
| 579 | { |
| 580 | unsigned short rgba = source[x]; |
| 581 | dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); |
| 582 | dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); |
| 583 | dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); |
| 584 | dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | void loadRGBA5551DataToBGRA(int width, int height, int depth, |
| 591 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 592 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 593 | { |
| 594 | const unsigned short *source = NULL; |
| 595 | unsigned char *dest = NULL; |
| 596 | |
| 597 | for (int z = 0; z < depth; z++) |
| 598 | { |
| 599 | for (int y = 0; y < height; y++) |
| 600 | { |
| 601 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 602 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 603 | for (int x = 0; x < width; x++) |
| 604 | { |
| 605 | unsigned short rgba = source[x]; |
| 606 | dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); |
| 607 | dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); |
| 608 | dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 609 | dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | void loadRGBA5551DataToRGBA(int width, int height, int depth, |
| 615 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 616 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 617 | { |
| 618 | const unsigned short *source = NULL; |
| 619 | unsigned char *dest = NULL; |
| 620 | |
| 621 | for (int z = 0; z < depth; z++) |
| 622 | { |
| 623 | for (int y = 0; y < height; y++) |
| 624 | { |
| 625 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 626 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 627 | for (int x = 0; x < width; x++) |
| 628 | { |
| 629 | unsigned short rgba = source[x]; |
| 630 | dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 631 | dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); |
| 632 | dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); |
| 633 | dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | void loadRGBAFloatDataToRGBA(int width, int height, int depth, |
| 640 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 641 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 642 | { |
| 643 | const float *source = NULL; |
| 644 | float *dest = NULL; |
| 645 | |
| 646 | for (int z = 0; z < depth; z++) |
| 647 | { |
| 648 | for (int y = 0; y < height; y++) |
| 649 | { |
| 650 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 651 | dest = offsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 652 | memcpy(dest, source, width * 16); |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | void loadRGBAHalfFloatDataToRGBA(int width, int height, int depth, |
| 658 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 659 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 660 | { |
| 661 | const unsigned char *source = NULL; |
| 662 | unsigned char *dest = NULL; |
| 663 | |
| 664 | for (int z = 0; z < depth; z++) |
| 665 | { |
| 666 | for (int y = 0; y < height; y++) |
| 667 | { |
| 668 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 669 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 670 | memcpy(dest, source, width * 8); |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | void loadBGRADataToBGRA(int width, int height, int depth, |
| 676 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 677 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 678 | { |
| 679 | const unsigned char *source = NULL; |
| 680 | unsigned char *dest = NULL; |
| 681 | |
| 682 | for (int z = 0; z < depth; z++) |
| 683 | { |
| 684 | for (int y = 0; y < height; y++) |
| 685 | { |
| 686 | source = offsetDataPointer<unsigned char>(input, y, z, inputRowPitch, inputDepthPitch); |
| 687 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 688 | memcpy(dest, source, width*4); |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
shannonwoods@chromium.org | 5d4468e | 2013-05-30 00:13:56 +0000 | [diff] [blame] | 693 | void loadRGBA2101010ToNative(int width, int height, int depth, |
| 694 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 695 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 696 | { |
| 697 | const unsigned int *source = NULL; |
| 698 | unsigned int *dest = NULL; |
| 699 | |
| 700 | for (int z = 0; z < depth; z++) |
| 701 | { |
| 702 | for (int y = 0; y < height; y++) |
| 703 | { |
| 704 | source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch); |
| 705 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 706 | memcpy(dest, source, width * sizeof(unsigned int)); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | void loadRGBA2101010ToRGBA(int width, int height, int depth, |
| 712 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 713 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 714 | { |
| 715 | const unsigned int *source = NULL; |
| 716 | unsigned char *dest = NULL; |
| 717 | |
| 718 | for (int z = 0; z < depth; z++) |
| 719 | { |
| 720 | for (int y = 0; y < height; y++) |
| 721 | { |
| 722 | source = offsetDataPointer<unsigned int>(input, y, z, inputRowPitch, inputDepthPitch); |
| 723 | dest = offsetDataPointer<unsigned char>(output, y, z, outputRowPitch, outputDepthPitch); |
| 724 | |
| 725 | for (int x = 0; x < width; x++) |
| 726 | { |
| 727 | unsigned int rgba = source[x]; |
| 728 | dest[4 * x + 0] = (rgba & 0x000003FF) >> 2; |
| 729 | dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12; |
| 730 | dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22; |
| 731 | dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55; |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 737 | void loadRGBHalfFloatDataTo999E5(int width, int height, int depth, |
| 738 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 739 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 740 | { |
| 741 | const unsigned short *source = NULL; |
| 742 | unsigned int *dest = NULL; |
| 743 | |
| 744 | for (int z = 0; z < depth; z++) |
| 745 | { |
| 746 | for (int y = 0; y < height; y++) |
| 747 | { |
| 748 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 749 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 750 | |
| 751 | for (int x = 0; x < width; x++) |
| 752 | { |
| 753 | dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]), |
| 754 | gl::float16ToFloat32(source[x * 3 + 1]), |
| 755 | gl::float16ToFloat32(source[x * 3 + 2])); |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void loadRGBFloatDataTo999E5(int width, int height, int depth, |
| 762 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 763 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 764 | { |
| 765 | const float *source = NULL; |
| 766 | unsigned int *dest = NULL; |
| 767 | |
| 768 | for (int z = 0; z < depth; z++) |
| 769 | { |
| 770 | for (int y = 0; y < height; y++) |
| 771 | { |
| 772 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 773 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 774 | |
| 775 | for (int x = 0; x < width; x++) |
| 776 | { |
| 777 | dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 783 | void loadRGBHalfFloatDataTo111110Float(int width, int height, int depth, |
| 784 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 785 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 786 | { |
| 787 | const unsigned short *source = NULL; |
| 788 | unsigned int *dest = NULL; |
| 789 | |
| 790 | for (int z = 0; z < depth; z++) |
| 791 | { |
| 792 | for (int y = 0; y < height; y++) |
| 793 | { |
| 794 | source = offsetDataPointer<unsigned short>(input, y, z, inputRowPitch, inputDepthPitch); |
| 795 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 796 | |
| 797 | for (int x = 0; x < width; x++) |
| 798 | { |
| 799 | dest[x] = (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 0])) << 0) | |
| 800 | (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 1])) << 11) | |
| 801 | (gl::float32ToFloat10(gl::float16ToFloat32(source[x * 3 + 2])) << 22); |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | void loadRGBFloatDataTo111110Float(int width, int height, int depth, |
| 808 | const void *input, unsigned int inputRowPitch, unsigned int inputDepthPitch, |
| 809 | void *output, unsigned int outputRowPitch, unsigned int outputDepthPitch) |
| 810 | { |
| 811 | const float *source = NULL; |
| 812 | unsigned int *dest = NULL; |
| 813 | |
| 814 | for (int z = 0; z < depth; z++) |
| 815 | { |
| 816 | for (int y = 0; y < height; y++) |
| 817 | { |
| 818 | source = offsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 819 | dest = offsetDataPointer<unsigned int>(output, y, z, outputRowPitch, outputDepthPitch); |
| 820 | |
| 821 | for (int x = 0; x < width; x++) |
| 822 | { |
| 823 | dest[x] = (gl::float32ToFloat11(source[x * 3 + 0]) << 0) | |
| 824 | (gl::float32ToFloat11(source[x * 3 + 1]) << 11) | |
| 825 | (gl::float32ToFloat10(source[x * 3 + 2]) << 22); |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 831 | } |