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