shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
| 2 | // |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 3 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 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 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 15 | void LoadA8ToRGBA8(size_t width, size_t height, size_t depth, |
| 16 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 17 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 18 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 19 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 20 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 21 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 22 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 23 | const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 24 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 25 | for (size_t x = 0; x < width; x++) |
| 26 | { |
| 27 | dest[x] = static_cast<uint32_t>(source[x]) << 24; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void LoadA8ToBGRA8(size_t width, size_t height, size_t depth, |
| 34 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 35 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 36 | { |
| 37 | // Same as loading to RGBA |
| 38 | LoadA8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch); |
| 39 | } |
| 40 | |
| 41 | void LoadA32FToRGBA32F(size_t width, size_t height, size_t depth, |
| 42 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 43 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 44 | { |
| 45 | for (size_t z = 0; z < depth; z++) |
| 46 | { |
| 47 | for (size_t y = 0; y < height; y++) |
| 48 | { |
| 49 | const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 50 | float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 51 | for (size_t x = 0; x < width; x++) |
| 52 | { |
| 53 | dest[4 * x + 0] = 0.0f; |
| 54 | dest[4 * x + 1] = 0.0f; |
| 55 | dest[4 * x + 2] = 0.0f; |
| 56 | dest[4 * x + 3] = source[x]; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void LoadA16FToRGBA16F(size_t width, size_t height, size_t depth, |
| 63 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 64 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 65 | { |
| 66 | for (size_t z = 0; z < depth; z++) |
| 67 | { |
| 68 | for (size_t y = 0; y < height; y++) |
| 69 | { |
| 70 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 71 | uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 72 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 73 | { |
| 74 | dest[4 * x + 0] = 0; |
| 75 | dest[4 * x + 1] = 0; |
| 76 | dest[4 * x + 2] = 0; |
| 77 | dest[4 * x + 3] = source[x]; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 83 | void LoadL8ToRGBA8(size_t width, size_t height, size_t depth, |
| 84 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 85 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 86 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 87 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 88 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 89 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 90 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 91 | const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 92 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 93 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 94 | { |
| 95 | dest[4 * x + 0] = source[x]; |
| 96 | dest[4 * x + 1] = source[x]; |
| 97 | dest[4 * x + 2] = source[x]; |
| 98 | dest[4 * x + 3] = 0xFF; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 104 | void LoadL8ToBGRA8(size_t width, size_t height, size_t depth, |
| 105 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 106 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 107 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 108 | // Same as loading to RGBA |
| 109 | LoadL8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch); |
| 110 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 111 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 112 | void LoadL32FToRGBA32F(size_t width, size_t height, size_t depth, |
| 113 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 114 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 115 | { |
| 116 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 117 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 118 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 119 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 120 | const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 121 | float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 122 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 123 | { |
| 124 | dest[4 * x + 0] = source[x]; |
| 125 | dest[4 * x + 1] = source[x]; |
| 126 | dest[4 * x + 2] = source[x]; |
| 127 | dest[4 * x + 3] = 1.0f; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 133 | void LoadL16FToRGBA16F(size_t width, size_t height, size_t depth, |
| 134 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 135 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 136 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 137 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 138 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 139 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 140 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 141 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 142 | uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 143 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 144 | { |
| 145 | dest[4 * x + 0] = source[x]; |
| 146 | dest[4 * x + 1] = source[x]; |
| 147 | dest[4 * x + 2] = source[x]; |
Geoff Lang | b69d39b | 2014-05-06 11:49:22 -0400 | [diff] [blame] | 148 | dest[4 * x + 3] = gl::Float16One; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 154 | void LoadLA8ToRGBA8(size_t width, size_t height, size_t depth, |
| 155 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 156 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 157 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 158 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 159 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 160 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 161 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 162 | const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 163 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 164 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 165 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 166 | dest[4 * x + 0] = source[2 * x + 0]; |
| 167 | dest[4 * x + 1] = source[2 * x + 0]; |
| 168 | dest[4 * x + 2] = source[2 * x + 0]; |
| 169 | dest[4 * x + 3] = source[2 * x + 1]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 175 | void LoadLA8ToBGRA8(size_t width, size_t height, size_t depth, |
| 176 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 177 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 178 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 179 | // Same as loading to RGBA |
| 180 | LoadLA8ToRGBA8(width, height, depth, input, inputRowPitch, inputDepthPitch, output, outputRowPitch, outputDepthPitch); |
| 181 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 182 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 183 | void LoadLA32FToRGBA32F(size_t width, size_t height, size_t depth, |
| 184 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 185 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 186 | { |
| 187 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 188 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 189 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 190 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 191 | const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 192 | float *dest = OffsetDataPointer<float>(output, y, z, outputRowPitch, outputDepthPitch); |
| 193 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 194 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 195 | dest[4 * x + 0] = source[2 * x + 0]; |
| 196 | dest[4 * x + 1] = source[2 * x + 0]; |
| 197 | dest[4 * x + 2] = source[2 * x + 0]; |
| 198 | dest[4 * x + 3] = source[2 * x + 1]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 204 | void LoadLA16FToRGBA16F(size_t width, size_t height, size_t depth, |
| 205 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 206 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 207 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 208 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 209 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 210 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 211 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 212 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 213 | uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 214 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 215 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 216 | dest[4 * x + 0] = source[2 * x + 0]; |
| 217 | dest[4 * x + 1] = source[2 * x + 0]; |
| 218 | dest[4 * x + 2] = source[2 * x + 0]; |
| 219 | dest[4 * x + 3] = source[2 * x + 1]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 225 | void LoadRGB8ToBGRX8(size_t width, size_t height, size_t depth, |
| 226 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 227 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 228 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 229 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 230 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 231 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 232 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 233 | const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 234 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 235 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 236 | { |
| 237 | dest[4 * x + 0] = source[x * 3 + 2]; |
| 238 | dest[4 * x + 1] = source[x * 3 + 1]; |
| 239 | dest[4 * x + 2] = source[x * 3 + 0]; |
| 240 | dest[4 * x + 3] = 0xFF; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 246 | void LoadRG8ToBGRX8(size_t width, size_t height, size_t depth, |
| 247 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 248 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 249 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 250 | for (size_t z = 0; z < depth; z++) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 251 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 252 | for (size_t y = 0; y < height; y++) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 253 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 254 | const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 255 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 256 | for (size_t x = 0; x < width; x++) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 257 | { |
| 258 | dest[4 * x + 0] = 0x00; |
| 259 | dest[4 * x + 1] = source[x * 2 + 1]; |
| 260 | dest[4 * x + 2] = source[x * 2 + 0]; |
| 261 | dest[4 * x + 3] = 0xFF; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 267 | void LoadR8ToBGRX8(size_t width, size_t height, size_t depth, |
| 268 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 269 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 270 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 271 | for (size_t z = 0; z < depth; z++) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 272 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 273 | for (size_t y = 0; y < height; y++) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 274 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 275 | const uint8_t *source = OffsetDataPointer<uint8_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 276 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 277 | for (size_t x = 0; x < width; x++) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 278 | { |
| 279 | dest[4 * x + 0] = 0x00; |
| 280 | dest[4 * x + 1] = 0x00; |
| 281 | dest[4 * x + 2] = source[x]; |
| 282 | dest[4 * x + 3] = 0xFF; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 288 | void LoadR5G6B5ToBGRA8(size_t width, size_t height, size_t depth, |
| 289 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 290 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 291 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 292 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 293 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 294 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 295 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 296 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 297 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 298 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 299 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 300 | uint16_t rgb = source[x]; |
| 301 | dest[4 * x + 0] = ((rgb & 0x001F) << 3) | ((rgb & 0x001F) >> 2); |
| 302 | dest[4 * x + 1] = ((rgb & 0x07E0) >> 3) | ((rgb & 0x07E0) >> 9); |
| 303 | dest[4 * x + 2] = ((rgb & 0xF800) >> 8) | ((rgb & 0xF800) >> 13); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 304 | dest[4 * x + 3] = 0xFF; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 310 | void LoadR5G6B5ToRGBA8(size_t width, size_t height, size_t depth, |
| 311 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 312 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | 36d0be9 | 2013-05-30 00:15:59 +0000 | [diff] [blame] | 313 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 314 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | 36d0be9 | 2013-05-30 00:15:59 +0000 | [diff] [blame] | 315 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 316 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | 36d0be9 | 2013-05-30 00:15:59 +0000 | [diff] [blame] | 317 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 318 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 319 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 320 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | 36d0be9 | 2013-05-30 00:15:59 +0000 | [diff] [blame] | 321 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 322 | uint16_t rgb = source[x]; |
| 323 | dest[4 * x + 0] = ((rgb & 0xF800) >> 8) | ((rgb & 0xF800) >> 13); |
| 324 | dest[4 * x + 1] = ((rgb & 0x07E0) >> 3) | ((rgb & 0x07E0) >> 9); |
| 325 | dest[4 * x + 2] = ((rgb & 0x001F) << 3) | ((rgb & 0x001F) >> 2); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 326 | dest[4 * x + 3] = 0xFF; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 332 | void LoadRGBA8ToBGRA8(size_t width, size_t height, size_t depth, |
| 333 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 334 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 335 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 336 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 337 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 338 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 339 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 340 | const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 341 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 342 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 343 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 344 | uint32_t rgba = source[x]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 345 | dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 351 | void LoadRGBA4ToBGRA8(size_t width, size_t height, size_t depth, |
| 352 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 353 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 354 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 355 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 356 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 357 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 358 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 359 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 360 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 361 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 362 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 363 | uint16_t rgba = source[x]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 364 | dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); |
| 365 | dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); |
| 366 | dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); |
| 367 | dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 373 | void LoadRGBA4ToRGBA8(size_t width, size_t height, size_t depth, |
| 374 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 375 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 376 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 377 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 378 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 379 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 380 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 381 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 382 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 383 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 384 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 385 | uint16_t rgba = source[x]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 386 | dest[4 * x + 0] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12); |
| 387 | dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8); |
| 388 | dest[4 * x + 2] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4); |
| 389 | dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 395 | void LoadBGRA4ToBGRA8(size_t width, size_t height, size_t depth, |
| 396 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 397 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 398 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 399 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 400 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 401 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 402 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 403 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 404 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 405 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 406 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 407 | uint16_t bgra = source[x]; |
| 408 | dest[4 * x + 0] = ((bgra & 0xF000) >> 8) | ((bgra & 0xF000) >> 12); |
| 409 | dest[4 * x + 1] = ((bgra & 0x0F00) >> 4) | ((bgra & 0x0F00) >> 8); |
| 410 | dest[4 * x + 2] = ((bgra & 0x00F0) << 0) | ((bgra & 0x00F0) >> 4); |
| 411 | dest[4 * x + 3] = ((bgra & 0x000F) << 4) | ((bgra & 0x000F) >> 0); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | void LoadRGB5A1ToBGRA8(size_t width, size_t height, size_t depth, |
| 418 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 419 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 420 | { |
| 421 | for (size_t z = 0; z < depth; z++) |
| 422 | { |
| 423 | for (size_t y = 0; y < height; y++) |
| 424 | { |
| 425 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 426 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 427 | for (size_t x = 0; x < width; x++) |
| 428 | { |
| 429 | uint16_t rgba = source[x]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 430 | dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); |
| 431 | dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); |
| 432 | dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 433 | dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 438 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 439 | void LoadRGB5A1ToRGBA8(size_t width, size_t height, size_t depth, |
| 440 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 441 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 442 | { |
| 443 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 444 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 445 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 446 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 447 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 448 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 449 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 450 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 451 | uint16_t rgba = source[x]; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 452 | dest[4 * x + 0] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13); |
| 453 | dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8); |
| 454 | dest[4 * x + 2] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3); |
| 455 | dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 461 | |
| 462 | void LoadBGR5A1ToBGRA8(size_t width, size_t height, size_t depth, |
| 463 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 464 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 465 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 466 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 467 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 468 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 469 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 470 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 471 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 472 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | 5d4468e | 2013-05-30 00:13:56 +0000 | [diff] [blame] | 473 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 474 | uint16_t bgra = source[x]; |
| 475 | dest[4 * x + 0] = ((bgra & 0xF800) >> 8) | ((bgra & 0xF800) >> 13); |
| 476 | dest[4 * x + 1] = ((bgra & 0x07C0) >> 3) | ((bgra & 0x07C0) >> 8); |
| 477 | dest[4 * x + 2] = ((bgra & 0x003E) << 2) | ((bgra & 0x003E) >> 3); |
| 478 | dest[4 * x + 3] = (bgra & 0x0001) ? 0xFF : 0; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | void LoadRGB10A2ToRGBA8(size_t width, size_t height, size_t depth, |
| 485 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 486 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
| 487 | { |
| 488 | for (size_t z = 0; z < depth; z++) |
| 489 | { |
| 490 | for (size_t y = 0; y < height; y++) |
| 491 | { |
| 492 | const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 493 | uint8_t *dest = OffsetDataPointer<uint8_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 494 | for (size_t x = 0; x < width; x++) |
| 495 | { |
| 496 | uint32_t rgba = source[x]; |
shannonwoods@chromium.org | 5d4468e | 2013-05-30 00:13:56 +0000 | [diff] [blame] | 497 | dest[4 * x + 0] = (rgba & 0x000003FF) >> 2; |
| 498 | dest[4 * x + 1] = (rgba & 0x000FFC00) >> 12; |
| 499 | dest[4 * x + 2] = (rgba & 0x3FF00000) >> 22; |
| 500 | dest[4 * x + 3] = ((rgba & 0xC0000000) >> 30) * 0x55; |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 506 | void LoadRGB16FToRGB9E5(size_t width, size_t height, size_t depth, |
| 507 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 508 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 509 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 510 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 511 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 512 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 513 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 514 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 515 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 516 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 517 | { |
| 518 | dest[x] = gl::convertRGBFloatsTo999E5(gl::float16ToFloat32(source[x * 3 + 0]), |
| 519 | gl::float16ToFloat32(source[x * 3 + 1]), |
| 520 | gl::float16ToFloat32(source[x * 3 + 2])); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 526 | void LoadRGB32FToRGB9E5(size_t width, size_t height, size_t depth, |
| 527 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 528 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 529 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 530 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 531 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 532 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 533 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 534 | const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 535 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 536 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | 92b9cd5 | 2013-05-30 00:14:48 +0000 | [diff] [blame] | 537 | { |
| 538 | dest[x] = gl::convertRGBFloatsTo999E5(source[x * 3 + 0], source[x * 3 + 1], source[x * 3 + 2]); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 544 | void LoadRGB16FToRG11B10F(size_t width, size_t height, size_t depth, |
| 545 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 546 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 547 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 548 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 549 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 550 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 551 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 552 | const uint16_t *source = OffsetDataPointer<uint16_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 553 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 554 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 555 | { |
| 556 | dest[x] = (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 0])) << 0) | |
| 557 | (gl::float32ToFloat11(gl::float16ToFloat32(source[x * 3 + 1])) << 11) | |
| 558 | (gl::float32ToFloat10(gl::float16ToFloat32(source[x * 3 + 2])) << 22); |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 564 | void LoadRGB32FToRG11B10F(size_t width, size_t height, size_t depth, |
| 565 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 566 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 567 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 568 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 569 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 570 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 571 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 572 | const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 573 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 574 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | a43d829 | 2013-05-30 00:15:50 +0000 | [diff] [blame] | 575 | { |
| 576 | dest[x] = (gl::float32ToFloat11(source[x * 3 + 0]) << 0) | |
| 577 | (gl::float32ToFloat11(source[x * 3 + 1]) << 11) | |
| 578 | (gl::float32ToFloat10(source[x * 3 + 2]) << 22); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 584 | void LoadG8R24ToR24G8(size_t width, size_t height, size_t depth, |
| 585 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 586 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
Geoff Lang | 4133f5c | 2013-10-10 13:51:18 -0400 | [diff] [blame] | 587 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 588 | for (size_t z = 0; z < depth; z++) |
Geoff Lang | 4133f5c | 2013-10-10 13:51:18 -0400 | [diff] [blame] | 589 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 590 | for (size_t y = 0; y < height; y++) |
Geoff Lang | 4133f5c | 2013-10-10 13:51:18 -0400 | [diff] [blame] | 591 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 592 | const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 593 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 594 | for (size_t x = 0; x < width; x++) |
Geoff Lang | 4133f5c | 2013-10-10 13:51:18 -0400 | [diff] [blame] | 595 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 596 | uint32_t d = source[x] >> 8; |
| 597 | uint8_t s = source[x] & 0xFF; |
Geoff Lang | 5c9a29a | 2014-02-11 10:26:24 -0500 | [diff] [blame] | 598 | dest[x] = d | (s << 24); |
Geoff Lang | 4133f5c | 2013-10-10 13:51:18 -0400 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 604 | void LoadRGB32FToRGBA16F(size_t width, size_t height, size_t depth, |
| 605 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 606 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
shannonwoods@chromium.org | de7e6a2 | 2013-05-30 00:16:46 +0000 | [diff] [blame] | 607 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 608 | for (size_t z = 0; z < depth; z++) |
shannonwoods@chromium.org | de7e6a2 | 2013-05-30 00:16:46 +0000 | [diff] [blame] | 609 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 610 | for (size_t y = 0; y < height; y++) |
shannonwoods@chromium.org | de7e6a2 | 2013-05-30 00:16:46 +0000 | [diff] [blame] | 611 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 612 | const float *source = OffsetDataPointer<float>(input, y, z, inputRowPitch, inputDepthPitch); |
| 613 | uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 614 | for (size_t x = 0; x < width; x++) |
shannonwoods@chromium.org | de7e6a2 | 2013-05-30 00:16:46 +0000 | [diff] [blame] | 615 | { |
| 616 | dest[x * 4 + 0] = gl::float32ToFloat16(source[x * 3 + 0]); |
| 617 | dest[x * 4 + 1] = gl::float32ToFloat16(source[x * 3 + 1]); |
| 618 | dest[x * 4 + 2] = gl::float32ToFloat16(source[x * 3 + 2]); |
| 619 | dest[x * 4 + 3] = gl::Float16One; |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 625 | void LoadR32ToR16(size_t width, size_t height, size_t depth, |
| 626 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 627 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
Geoff Lang | 8746546 | 2013-06-17 16:28:54 -0400 | [diff] [blame] | 628 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 629 | for (size_t z = 0; z < depth; z++) |
Geoff Lang | 8746546 | 2013-06-17 16:28:54 -0400 | [diff] [blame] | 630 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 631 | for (size_t y = 0; y < height; y++) |
Geoff Lang | 8746546 | 2013-06-17 16:28:54 -0400 | [diff] [blame] | 632 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 633 | const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 634 | uint16_t *dest = OffsetDataPointer<uint16_t>(output, y, z, outputRowPitch, outputDepthPitch); |
| 635 | for (size_t x = 0; x < width; x++) |
Geoff Lang | 8746546 | 2013-06-17 16:28:54 -0400 | [diff] [blame] | 636 | { |
| 637 | dest[x] = source[x] >> 16; |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 643 | void LoadR32ToR24G8(size_t width, size_t height, size_t depth, |
| 644 | const uint8_t *input, size_t inputRowPitch, size_t inputDepthPitch, |
| 645 | uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 646 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 647 | for (size_t z = 0; z < depth; z++) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 648 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 649 | for (size_t y = 0; y < height; y++) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 650 | { |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 651 | const uint32_t *source = OffsetDataPointer<uint32_t>(input, y, z, inputRowPitch, inputDepthPitch); |
| 652 | uint32_t *dest = OffsetDataPointer<uint32_t>(output, y, z, outputRowPitch, outputDepthPitch); |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 653 | |
Geoff Lang | 86846e2 | 2014-06-03 15:48:54 -0400 | [diff] [blame^] | 654 | for (size_t x = 0; x < width; x++) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 655 | { |
| 656 | dest[x] = source[x] >> 8; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 662 | } |