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