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