| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Mesa 3-D graphics library |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 4 | * Version: 4.1 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 5 | * |
| Brian Paul | df7bd4b | 2002-04-24 20:11:20 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 7 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 14 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 15 | * The above copyright notice and this permission notice shall be included |
| 16 | * in all copies or substantial portions of the Software. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 17 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 22 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 26 | #include "glheader.h" |
| Brian Paul | 3c63452 | 2002-10-24 23:57:19 +0000 | [diff] [blame] | 27 | #include "imports.h" |
| Brian Paul | c893a01 | 2000-10-28 20:41:13 +0000 | [diff] [blame] | 28 | #include "colormac.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 29 | #include "context.h" |
| 30 | #include "macros.h" |
| 31 | #include "pixel.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 32 | #include "mtypes.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | /**********************************************************************/ |
| 36 | /***** glPixelZoom *****/ |
| 37 | /**********************************************************************/ |
| 38 | |
| 39 | |
| 40 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 41 | void |
| 42 | _mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 43 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 44 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 45 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 46 | if (ctx->Pixel.ZoomX == xfactor && |
| 47 | ctx->Pixel.ZoomY == yfactor) |
| 48 | return; |
| 49 | |
| 50 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 51 | ctx->Pixel.ZoomX = xfactor; |
| 52 | ctx->Pixel.ZoomY = yfactor; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | |
| 57 | /**********************************************************************/ |
| 58 | /***** glPixelStore *****/ |
| 59 | /**********************************************************************/ |
| 60 | |
| 61 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 62 | void |
| 63 | _mesa_PixelStorei( GLenum pname, GLint param ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 64 | { |
| 65 | /* NOTE: this call can't be compiled into the display list */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 66 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 67 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 68 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 69 | switch (pname) { |
| 70 | case GL_PACK_SWAP_BYTES: |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 71 | if (param == (GLint)ctx->Pack.SwapBytes) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 72 | return; |
| 73 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 74 | ctx->Pack.SwapBytes = param ? GL_TRUE : GL_FALSE; |
| 75 | break; |
| 76 | case GL_PACK_LSB_FIRST: |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 77 | if (param == (GLint)ctx->Pack.LsbFirst) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 78 | return; |
| 79 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 80 | ctx->Pack.LsbFirst = param ? GL_TRUE : GL_FALSE; |
| 81 | break; |
| 82 | case GL_PACK_ROW_LENGTH: |
| 83 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 84 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 85 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 86 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 87 | if (ctx->Pack.RowLength == param) |
| 88 | return; |
| 89 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 90 | ctx->Pack.RowLength = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 91 | break; |
| 92 | case GL_PACK_IMAGE_HEIGHT: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 93 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 94 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 95 | return; |
| 96 | } |
| 97 | if (ctx->Pack.ImageHeight == param) |
| 98 | return; |
| 99 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 100 | ctx->Pack.ImageHeight = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 101 | break; |
| 102 | case GL_PACK_SKIP_PIXELS: |
| 103 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 104 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 105 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 106 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 107 | if (ctx->Pack.SkipPixels == param) |
| 108 | return; |
| 109 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 110 | ctx->Pack.SkipPixels = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 111 | break; |
| 112 | case GL_PACK_SKIP_ROWS: |
| 113 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 114 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 115 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 116 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 117 | if (ctx->Pack.SkipRows == param) |
| 118 | return; |
| 119 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 120 | ctx->Pack.SkipRows = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 121 | break; |
| Brian Paul | a5b6633 | 2000-10-19 20:09:47 +0000 | [diff] [blame] | 122 | case GL_PACK_SKIP_IMAGES: |
| 123 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 124 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 125 | return; |
| Brian Paul | a5b6633 | 2000-10-19 20:09:47 +0000 | [diff] [blame] | 126 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 127 | if (ctx->Pack.SkipImages == param) |
| 128 | return; |
| 129 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 130 | ctx->Pack.SkipImages = param; |
| Brian Paul | a5b6633 | 2000-10-19 20:09:47 +0000 | [diff] [blame] | 131 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 132 | case GL_PACK_ALIGNMENT: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 133 | if (param!=1 && param!=2 && param!=4 && param!=8) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 134 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 135 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 136 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 137 | if (ctx->Pack.Alignment == param) |
| 138 | return; |
| 139 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 140 | ctx->Pack.Alignment = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 141 | break; |
| Brian Paul | 551b65f | 2002-09-21 17:34:56 +0000 | [diff] [blame] | 142 | case GL_PACK_INVERT_MESA: |
| 143 | if (!ctx->Extensions.MESA_pack_invert) { |
| 144 | _mesa_error( ctx, GL_INVALID_ENUM, "glPixelstore(pname)" ); |
| 145 | return; |
| 146 | } |
| 147 | if (ctx->Pack.Invert == param) |
| 148 | return; |
| 149 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 150 | ctx->Pack.Invert = param; |
| 151 | break; |
| 152 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 153 | case GL_UNPACK_SWAP_BYTES: |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 154 | if (param == (GLint)ctx->Unpack.SwapBytes) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 155 | return; |
| 156 | if ((GLint)ctx->Unpack.SwapBytes == param) |
| 157 | return; |
| 158 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 159 | ctx->Unpack.SwapBytes = param ? GL_TRUE : GL_FALSE; |
| 160 | break; |
| 161 | case GL_UNPACK_LSB_FIRST: |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 162 | if (param == (GLint)ctx->Unpack.LsbFirst) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 163 | return; |
| 164 | if ((GLint)ctx->Unpack.LsbFirst == param) |
| 165 | return; |
| 166 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 167 | ctx->Unpack.LsbFirst = param ? GL_TRUE : GL_FALSE; |
| 168 | break; |
| 169 | case GL_UNPACK_ROW_LENGTH: |
| 170 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 171 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 172 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 173 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 174 | if (ctx->Unpack.RowLength == param) |
| 175 | return; |
| 176 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 177 | ctx->Unpack.RowLength = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 178 | break; |
| 179 | case GL_UNPACK_IMAGE_HEIGHT: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 180 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 181 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | if (ctx->Unpack.ImageHeight == param) |
| 185 | return; |
| 186 | |
| 187 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 188 | ctx->Unpack.ImageHeight = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 189 | break; |
| 190 | case GL_UNPACK_SKIP_PIXELS: |
| 191 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 192 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 193 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 194 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 195 | if (ctx->Unpack.SkipPixels == param) |
| 196 | return; |
| 197 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 198 | ctx->Unpack.SkipPixels = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 199 | break; |
| 200 | case GL_UNPACK_SKIP_ROWS: |
| 201 | if (param<0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 202 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 203 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 204 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 205 | if (ctx->Unpack.SkipRows == param) |
| 206 | return; |
| 207 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 208 | ctx->Unpack.SkipRows = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 209 | break; |
| Brian Paul | a5b6633 | 2000-10-19 20:09:47 +0000 | [diff] [blame] | 210 | case GL_UNPACK_SKIP_IMAGES: |
| 211 | if (param < 0) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 212 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 213 | return; |
| Brian Paul | a5b6633 | 2000-10-19 20:09:47 +0000 | [diff] [blame] | 214 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 215 | if (ctx->Unpack.SkipImages == param) |
| 216 | return; |
| 217 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 218 | ctx->Unpack.SkipImages = param; |
| Brian Paul | a5b6633 | 2000-10-19 20:09:47 +0000 | [diff] [blame] | 219 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 220 | case GL_UNPACK_ALIGNMENT: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 221 | if (param!=1 && param!=2 && param!=4 && param!=8) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 222 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 223 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 224 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 225 | if (ctx->Unpack.Alignment == param) |
| 226 | return; |
| 227 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 228 | ctx->Unpack.Alignment = param; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 229 | break; |
| Brian Paul | c5b9950 | 2002-09-21 16:51:25 +0000 | [diff] [blame] | 230 | case GL_UNPACK_CLIENT_STORAGE_APPLE: |
| 231 | if (param == (GLint)ctx->Unpack.ClientStorage) |
| 232 | return; |
| 233 | FLUSH_VERTICES(ctx, _NEW_PACKUNPACK); |
| 234 | ctx->Unpack.ClientStorage = param ? GL_TRUE : GL_FALSE; |
| 235 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 236 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 237 | _mesa_error( ctx, GL_INVALID_ENUM, "glPixelStore" ); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 238 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 243 | void |
| 244 | _mesa_PixelStoref( GLenum pname, GLfloat param ) |
| 245 | { |
| 246 | _mesa_PixelStorei( pname, (GLint) param ); |
| 247 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 248 | |
| 249 | |
| 250 | |
| 251 | /**********************************************************************/ |
| 252 | /***** glPixelMap *****/ |
| 253 | /**********************************************************************/ |
| 254 | |
| 255 | |
| 256 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 257 | void |
| 258 | _mesa_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 259 | { |
| 260 | GLint i; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 261 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 262 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 263 | |
| Brian Paul | df7bd4b | 2002-04-24 20:11:20 +0000 | [diff] [blame] | 264 | if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 265 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 266 | return; |
| 267 | } |
| 268 | |
| Brian Paul | df7bd4b | 2002-04-24 20:11:20 +0000 | [diff] [blame] | 269 | if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 270 | /* test that mapsize is a power of two */ |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 271 | if (_mesa_bitcount((GLuint) mapsize) != 1) { |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 272 | _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | } |
| 276 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 277 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| 278 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 279 | switch (map) { |
| 280 | case GL_PIXEL_MAP_S_TO_S: |
| 281 | ctx->Pixel.MapStoSsize = mapsize; |
| 282 | for (i=0;i<mapsize;i++) { |
| 283 | ctx->Pixel.MapStoS[i] = (GLint) values[i]; |
| 284 | } |
| 285 | break; |
| 286 | case GL_PIXEL_MAP_I_TO_I: |
| 287 | ctx->Pixel.MapItoIsize = mapsize; |
| 288 | for (i=0;i<mapsize;i++) { |
| 289 | ctx->Pixel.MapItoI[i] = (GLint) values[i]; |
| 290 | } |
| 291 | break; |
| 292 | case GL_PIXEL_MAP_I_TO_R: |
| 293 | ctx->Pixel.MapItoRsize = mapsize; |
| 294 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 295 | GLfloat val = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 296 | ctx->Pixel.MapItoR[i] = val; |
| 297 | ctx->Pixel.MapItoR8[i] = (GLint) (val * 255.0F); |
| 298 | } |
| 299 | break; |
| 300 | case GL_PIXEL_MAP_I_TO_G: |
| 301 | ctx->Pixel.MapItoGsize = mapsize; |
| 302 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 303 | GLfloat val = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 304 | ctx->Pixel.MapItoG[i] = val; |
| 305 | ctx->Pixel.MapItoG8[i] = (GLint) (val * 255.0F); |
| 306 | } |
| 307 | break; |
| 308 | case GL_PIXEL_MAP_I_TO_B: |
| 309 | ctx->Pixel.MapItoBsize = mapsize; |
| 310 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 311 | GLfloat val = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 312 | ctx->Pixel.MapItoB[i] = val; |
| 313 | ctx->Pixel.MapItoB8[i] = (GLint) (val * 255.0F); |
| 314 | } |
| 315 | break; |
| 316 | case GL_PIXEL_MAP_I_TO_A: |
| 317 | ctx->Pixel.MapItoAsize = mapsize; |
| 318 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 319 | GLfloat val = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 320 | ctx->Pixel.MapItoA[i] = val; |
| 321 | ctx->Pixel.MapItoA8[i] = (GLint) (val * 255.0F); |
| 322 | } |
| 323 | break; |
| 324 | case GL_PIXEL_MAP_R_TO_R: |
| 325 | ctx->Pixel.MapRtoRsize = mapsize; |
| 326 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 327 | ctx->Pixel.MapRtoR[i] = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 328 | } |
| 329 | break; |
| 330 | case GL_PIXEL_MAP_G_TO_G: |
| 331 | ctx->Pixel.MapGtoGsize = mapsize; |
| 332 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 333 | ctx->Pixel.MapGtoG[i] = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 334 | } |
| 335 | break; |
| 336 | case GL_PIXEL_MAP_B_TO_B: |
| 337 | ctx->Pixel.MapBtoBsize = mapsize; |
| 338 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 339 | ctx->Pixel.MapBtoB[i] = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 340 | } |
| 341 | break; |
| 342 | case GL_PIXEL_MAP_A_TO_A: |
| 343 | ctx->Pixel.MapAtoAsize = mapsize; |
| 344 | for (i=0;i<mapsize;i++) { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 345 | ctx->Pixel.MapAtoA[i] = CLAMP( values[i], 0.0F, 1.0F ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 346 | } |
| 347 | break; |
| 348 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 349 | _mesa_error( ctx, GL_INVALID_ENUM, "glPixelMapfv(map)" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | |
| 354 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 355 | void |
| 356 | _mesa_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 357 | { |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 358 | const GLint n = MIN2(mapsize, MAX_PIXEL_MAP_TABLE); |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 359 | GLfloat fvalues[MAX_PIXEL_MAP_TABLE]; |
| 360 | GLint i; |
| 361 | if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) { |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 362 | for (i=0;i<n;i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 363 | fvalues[i] = (GLfloat) values[i]; |
| 364 | } |
| 365 | } |
| 366 | else { |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 367 | for (i=0;i<n;i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 368 | fvalues[i] = UINT_TO_FLOAT( values[i] ); |
| 369 | } |
| 370 | } |
| 371 | _mesa_PixelMapfv(map, mapsize, fvalues); |
| 372 | } |
| 373 | |
| 374 | |
| 375 | |
| 376 | void |
| 377 | _mesa_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values ) |
| 378 | { |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 379 | const GLint n = MIN2(mapsize, MAX_PIXEL_MAP_TABLE); |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 380 | GLfloat fvalues[MAX_PIXEL_MAP_TABLE]; |
| 381 | GLint i; |
| 382 | if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) { |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 383 | for (i=0;i<n;i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 384 | fvalues[i] = (GLfloat) values[i]; |
| 385 | } |
| 386 | } |
| 387 | else { |
| Brian Paul | aecfb51 | 2001-12-04 23:45:31 +0000 | [diff] [blame] | 388 | for (i=0;i<n;i++) { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 389 | fvalues[i] = USHORT_TO_FLOAT( values[i] ); |
| 390 | } |
| 391 | } |
| 392 | _mesa_PixelMapfv(map, mapsize, fvalues); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | |
| 397 | void |
| 398 | _mesa_GetPixelMapfv( GLenum map, GLfloat *values ) |
| 399 | { |
| 400 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 401 | GLint i; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 402 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 403 | |
| 404 | switch (map) { |
| 405 | case GL_PIXEL_MAP_I_TO_I: |
| 406 | for (i=0;i<ctx->Pixel.MapItoIsize;i++) { |
| 407 | values[i] = (GLfloat) ctx->Pixel.MapItoI[i]; |
| 408 | } |
| 409 | break; |
| 410 | case GL_PIXEL_MAP_S_TO_S: |
| 411 | for (i=0;i<ctx->Pixel.MapStoSsize;i++) { |
| 412 | values[i] = (GLfloat) ctx->Pixel.MapStoS[i]; |
| 413 | } |
| 414 | break; |
| 415 | case GL_PIXEL_MAP_I_TO_R: |
| 416 | MEMCPY(values,ctx->Pixel.MapItoR,ctx->Pixel.MapItoRsize*sizeof(GLfloat)); |
| 417 | break; |
| 418 | case GL_PIXEL_MAP_I_TO_G: |
| 419 | MEMCPY(values,ctx->Pixel.MapItoG,ctx->Pixel.MapItoGsize*sizeof(GLfloat)); |
| 420 | break; |
| 421 | case GL_PIXEL_MAP_I_TO_B: |
| 422 | MEMCPY(values,ctx->Pixel.MapItoB,ctx->Pixel.MapItoBsize*sizeof(GLfloat)); |
| 423 | break; |
| 424 | case GL_PIXEL_MAP_I_TO_A: |
| 425 | MEMCPY(values,ctx->Pixel.MapItoA,ctx->Pixel.MapItoAsize*sizeof(GLfloat)); |
| 426 | break; |
| 427 | case GL_PIXEL_MAP_R_TO_R: |
| 428 | MEMCPY(values,ctx->Pixel.MapRtoR,ctx->Pixel.MapRtoRsize*sizeof(GLfloat)); |
| 429 | break; |
| 430 | case GL_PIXEL_MAP_G_TO_G: |
| 431 | MEMCPY(values,ctx->Pixel.MapGtoG,ctx->Pixel.MapGtoGsize*sizeof(GLfloat)); |
| 432 | break; |
| 433 | case GL_PIXEL_MAP_B_TO_B: |
| 434 | MEMCPY(values,ctx->Pixel.MapBtoB,ctx->Pixel.MapBtoBsize*sizeof(GLfloat)); |
| 435 | break; |
| 436 | case GL_PIXEL_MAP_A_TO_A: |
| 437 | MEMCPY(values,ctx->Pixel.MapAtoA,ctx->Pixel.MapAtoAsize*sizeof(GLfloat)); |
| 438 | break; |
| 439 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 440 | _mesa_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
| 444 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 445 | void |
| 446 | _mesa_GetPixelMapuiv( GLenum map, GLuint *values ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 447 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 448 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 449 | GLint i; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 450 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 451 | |
| 452 | switch (map) { |
| 453 | case GL_PIXEL_MAP_I_TO_I: |
| 454 | MEMCPY(values, ctx->Pixel.MapItoI, ctx->Pixel.MapItoIsize*sizeof(GLint)); |
| 455 | break; |
| 456 | case GL_PIXEL_MAP_S_TO_S: |
| 457 | MEMCPY(values, ctx->Pixel.MapStoS, ctx->Pixel.MapStoSsize*sizeof(GLint)); |
| 458 | break; |
| 459 | case GL_PIXEL_MAP_I_TO_R: |
| 460 | for (i=0;i<ctx->Pixel.MapItoRsize;i++) { |
| 461 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoR[i] ); |
| 462 | } |
| 463 | break; |
| 464 | case GL_PIXEL_MAP_I_TO_G: |
| 465 | for (i=0;i<ctx->Pixel.MapItoGsize;i++) { |
| 466 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoG[i] ); |
| 467 | } |
| 468 | break; |
| 469 | case GL_PIXEL_MAP_I_TO_B: |
| 470 | for (i=0;i<ctx->Pixel.MapItoBsize;i++) { |
| 471 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoB[i] ); |
| 472 | } |
| 473 | break; |
| 474 | case GL_PIXEL_MAP_I_TO_A: |
| 475 | for (i=0;i<ctx->Pixel.MapItoAsize;i++) { |
| 476 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoA[i] ); |
| 477 | } |
| 478 | break; |
| 479 | case GL_PIXEL_MAP_R_TO_R: |
| 480 | for (i=0;i<ctx->Pixel.MapRtoRsize;i++) { |
| 481 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapRtoR[i] ); |
| 482 | } |
| 483 | break; |
| 484 | case GL_PIXEL_MAP_G_TO_G: |
| 485 | for (i=0;i<ctx->Pixel.MapGtoGsize;i++) { |
| 486 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapGtoG[i] ); |
| 487 | } |
| 488 | break; |
| 489 | case GL_PIXEL_MAP_B_TO_B: |
| 490 | for (i=0;i<ctx->Pixel.MapBtoBsize;i++) { |
| 491 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapBtoB[i] ); |
| 492 | } |
| 493 | break; |
| 494 | case GL_PIXEL_MAP_A_TO_A: |
| 495 | for (i=0;i<ctx->Pixel.MapAtoAsize;i++) { |
| 496 | values[i] = FLOAT_TO_UINT( ctx->Pixel.MapAtoA[i] ); |
| 497 | } |
| 498 | break; |
| 499 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 500 | _mesa_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
| 504 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 505 | void |
| 506 | _mesa_GetPixelMapusv( GLenum map, GLushort *values ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 507 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 508 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 509 | GLint i; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 510 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 511 | |
| 512 | switch (map) { |
| 513 | case GL_PIXEL_MAP_I_TO_I: |
| 514 | for (i=0;i<ctx->Pixel.MapItoIsize;i++) { |
| 515 | values[i] = (GLushort) ctx->Pixel.MapItoI[i]; |
| 516 | } |
| 517 | break; |
| 518 | case GL_PIXEL_MAP_S_TO_S: |
| 519 | for (i=0;i<ctx->Pixel.MapStoSsize;i++) { |
| 520 | values[i] = (GLushort) ctx->Pixel.MapStoS[i]; |
| 521 | } |
| 522 | break; |
| 523 | case GL_PIXEL_MAP_I_TO_R: |
| 524 | for (i=0;i<ctx->Pixel.MapItoRsize;i++) { |
| 525 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoR[i] ); |
| 526 | } |
| 527 | break; |
| 528 | case GL_PIXEL_MAP_I_TO_G: |
| 529 | for (i=0;i<ctx->Pixel.MapItoGsize;i++) { |
| 530 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoG[i] ); |
| 531 | } |
| 532 | break; |
| 533 | case GL_PIXEL_MAP_I_TO_B: |
| 534 | for (i=0;i<ctx->Pixel.MapItoBsize;i++) { |
| 535 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoB[i] ); |
| 536 | } |
| 537 | break; |
| 538 | case GL_PIXEL_MAP_I_TO_A: |
| 539 | for (i=0;i<ctx->Pixel.MapItoAsize;i++) { |
| 540 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoA[i] ); |
| 541 | } |
| 542 | break; |
| 543 | case GL_PIXEL_MAP_R_TO_R: |
| 544 | for (i=0;i<ctx->Pixel.MapRtoRsize;i++) { |
| 545 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapRtoR[i] ); |
| 546 | } |
| 547 | break; |
| 548 | case GL_PIXEL_MAP_G_TO_G: |
| 549 | for (i=0;i<ctx->Pixel.MapGtoGsize;i++) { |
| 550 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapGtoG[i] ); |
| 551 | } |
| 552 | break; |
| 553 | case GL_PIXEL_MAP_B_TO_B: |
| 554 | for (i=0;i<ctx->Pixel.MapBtoBsize;i++) { |
| 555 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapBtoB[i] ); |
| 556 | } |
| 557 | break; |
| 558 | case GL_PIXEL_MAP_A_TO_A: |
| 559 | for (i=0;i<ctx->Pixel.MapAtoAsize;i++) { |
| 560 | values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapAtoA[i] ); |
| 561 | } |
| 562 | break; |
| 563 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 564 | _mesa_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | |
| 569 | |
| 570 | /**********************************************************************/ |
| 571 | /***** glPixelTransfer *****/ |
| 572 | /**********************************************************************/ |
| 573 | |
| 574 | |
| 575 | /* |
| 576 | * Implements glPixelTransfer[fi] whether called immediately or from a |
| 577 | * display list. |
| 578 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 579 | void |
| 580 | _mesa_PixelTransferf( GLenum pname, GLfloat param ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 581 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 582 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 583 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 584 | |
| 585 | switch (pname) { |
| 586 | case GL_MAP_COLOR: |
| Brian Paul | f431a3f | 2001-07-13 20:07:37 +0000 | [diff] [blame] | 587 | if (ctx->Pixel.MapColorFlag == (param ? GL_TRUE : GL_FALSE)) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 588 | return; |
| 589 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 590 | ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE; |
| 591 | break; |
| 592 | case GL_MAP_STENCIL: |
| Brian Paul | f431a3f | 2001-07-13 20:07:37 +0000 | [diff] [blame] | 593 | if (ctx->Pixel.MapStencilFlag == (param ? GL_TRUE : GL_FALSE)) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 594 | return; |
| 595 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 596 | ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE; |
| 597 | break; |
| 598 | case GL_INDEX_SHIFT: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 599 | if (ctx->Pixel.IndexShift == (GLint) param) |
| 600 | return; |
| 601 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 602 | ctx->Pixel.IndexShift = (GLint) param; |
| 603 | break; |
| 604 | case GL_INDEX_OFFSET: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 605 | if (ctx->Pixel.IndexOffset == (GLint) param) |
| 606 | return; |
| 607 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 608 | ctx->Pixel.IndexOffset = (GLint) param; |
| 609 | break; |
| 610 | case GL_RED_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 611 | if (ctx->Pixel.RedScale == param) |
| 612 | return; |
| 613 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 614 | ctx->Pixel.RedScale = param; |
| 615 | break; |
| 616 | case GL_RED_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 617 | if (ctx->Pixel.RedBias == param) |
| 618 | return; |
| 619 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 620 | ctx->Pixel.RedBias = param; |
| 621 | break; |
| 622 | case GL_GREEN_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 623 | if (ctx->Pixel.GreenScale == param) |
| 624 | return; |
| 625 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 626 | ctx->Pixel.GreenScale = param; |
| 627 | break; |
| 628 | case GL_GREEN_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 629 | if (ctx->Pixel.GreenBias == param) |
| 630 | return; |
| 631 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 632 | ctx->Pixel.GreenBias = param; |
| 633 | break; |
| 634 | case GL_BLUE_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 635 | if (ctx->Pixel.BlueScale == param) |
| 636 | return; |
| 637 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 638 | ctx->Pixel.BlueScale = param; |
| 639 | break; |
| 640 | case GL_BLUE_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 641 | if (ctx->Pixel.BlueBias == param) |
| 642 | return; |
| 643 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 644 | ctx->Pixel.BlueBias = param; |
| 645 | break; |
| 646 | case GL_ALPHA_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 647 | if (ctx->Pixel.AlphaScale == param) |
| 648 | return; |
| 649 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 650 | ctx->Pixel.AlphaScale = param; |
| 651 | break; |
| 652 | case GL_ALPHA_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 653 | if (ctx->Pixel.AlphaBias == param) |
| 654 | return; |
| 655 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 656 | ctx->Pixel.AlphaBias = param; |
| 657 | break; |
| 658 | case GL_DEPTH_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 659 | if (ctx->Pixel.DepthScale == param) |
| 660 | return; |
| 661 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 662 | ctx->Pixel.DepthScale = param; |
| 663 | break; |
| 664 | case GL_DEPTH_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 665 | if (ctx->Pixel.DepthBias == param) |
| 666 | return; |
| 667 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 668 | ctx->Pixel.DepthBias = param; |
| 669 | break; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 670 | case GL_POST_COLOR_MATRIX_RED_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 671 | if (ctx->Pixel.PostColorMatrixScale[0] == param) |
| 672 | return; |
| 673 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 674 | ctx->Pixel.PostColorMatrixScale[0] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 675 | break; |
| 676 | case GL_POST_COLOR_MATRIX_RED_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 677 | if (ctx->Pixel.PostColorMatrixBias[0] == param) |
| 678 | return; |
| 679 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 680 | ctx->Pixel.PostColorMatrixBias[0] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 681 | break; |
| 682 | case GL_POST_COLOR_MATRIX_GREEN_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 683 | if (ctx->Pixel.PostColorMatrixScale[1] == param) |
| 684 | return; |
| 685 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 686 | ctx->Pixel.PostColorMatrixScale[1] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 687 | break; |
| 688 | case GL_POST_COLOR_MATRIX_GREEN_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 689 | if (ctx->Pixel.PostColorMatrixBias[1] == param) |
| 690 | return; |
| 691 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 692 | ctx->Pixel.PostColorMatrixBias[1] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 693 | break; |
| 694 | case GL_POST_COLOR_MATRIX_BLUE_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 695 | if (ctx->Pixel.PostColorMatrixScale[2] == param) |
| 696 | return; |
| 697 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 698 | ctx->Pixel.PostColorMatrixScale[2] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 699 | break; |
| 700 | case GL_POST_COLOR_MATRIX_BLUE_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 701 | if (ctx->Pixel.PostColorMatrixBias[2] == param) |
| 702 | return; |
| 703 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 704 | ctx->Pixel.PostColorMatrixBias[2] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 705 | break; |
| 706 | case GL_POST_COLOR_MATRIX_ALPHA_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 707 | if (ctx->Pixel.PostColorMatrixScale[3] == param) |
| 708 | return; |
| 709 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 710 | ctx->Pixel.PostColorMatrixScale[3] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 711 | break; |
| 712 | case GL_POST_COLOR_MATRIX_ALPHA_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 713 | if (ctx->Pixel.PostColorMatrixBias[3] == param) |
| 714 | return; |
| 715 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 716 | ctx->Pixel.PostColorMatrixBias[3] = param; |
| 717 | break; |
| 718 | case GL_POST_CONVOLUTION_RED_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 719 | if (ctx->Pixel.PostConvolutionScale[0] == param) |
| 720 | return; |
| 721 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 722 | ctx->Pixel.PostConvolutionScale[0] = param; |
| 723 | break; |
| 724 | case GL_POST_CONVOLUTION_RED_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 725 | if (ctx->Pixel.PostConvolutionBias[0] == param) |
| 726 | return; |
| 727 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 728 | ctx->Pixel.PostConvolutionBias[0] = param; |
| 729 | break; |
| 730 | case GL_POST_CONVOLUTION_GREEN_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 731 | if (ctx->Pixel.PostConvolutionScale[1] == param) |
| 732 | return; |
| 733 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 734 | ctx->Pixel.PostConvolutionScale[1] = param; |
| 735 | break; |
| 736 | case GL_POST_CONVOLUTION_GREEN_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 737 | if (ctx->Pixel.PostConvolutionBias[1] == param) |
| 738 | return; |
| 739 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 740 | ctx->Pixel.PostConvolutionBias[1] = param; |
| 741 | break; |
| 742 | case GL_POST_CONVOLUTION_BLUE_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 743 | if (ctx->Pixel.PostConvolutionScale[2] == param) |
| 744 | return; |
| 745 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 746 | ctx->Pixel.PostConvolutionScale[2] = param; |
| 747 | break; |
| 748 | case GL_POST_CONVOLUTION_BLUE_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 749 | if (ctx->Pixel.PostConvolutionBias[2] == param) |
| 750 | return; |
| 751 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 752 | ctx->Pixel.PostConvolutionBias[2] = param; |
| 753 | break; |
| 754 | case GL_POST_CONVOLUTION_ALPHA_SCALE: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 755 | if (ctx->Pixel.PostConvolutionScale[2] == param) |
| 756 | return; |
| 757 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 758 | ctx->Pixel.PostConvolutionScale[2] = param; |
| 759 | break; |
| 760 | case GL_POST_CONVOLUTION_ALPHA_BIAS: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 761 | if (ctx->Pixel.PostConvolutionBias[2] == param) |
| 762 | return; |
| 763 | FLUSH_VERTICES(ctx, _NEW_PIXEL); |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 764 | ctx->Pixel.PostConvolutionBias[2] = param; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 765 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 766 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 767 | _mesa_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 768 | return; |
| 769 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 773 | void |
| 774 | _mesa_PixelTransferi( GLenum pname, GLint param ) |
| 775 | { |
| 776 | _mesa_PixelTransferf( pname, (GLfloat) param ); |
| 777 | } |
| 778 | |
| 779 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 780 | |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 781 | /**********************************************************************/ |
| 782 | /***** Pixel processing functions ******/ |
| 783 | /**********************************************************************/ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 784 | |
| 785 | |
| 786 | /* |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 787 | * Apply scale and bias factors to an array of RGBA pixels. |
| 788 | */ |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 789 | void |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 790 | _mesa_scale_and_bias_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4], |
| 791 | GLfloat rScale, GLfloat gScale, |
| 792 | GLfloat bScale, GLfloat aScale, |
| 793 | GLfloat rBias, GLfloat gBias, |
| 794 | GLfloat bBias, GLfloat aBias) |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 795 | { |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 796 | if (rScale != 1.0 || rBias != 0.0) { |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 797 | GLuint i; |
| 798 | for (i = 0; i < n; i++) { |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 799 | rgba[i][RCOMP] = rgba[i][RCOMP] * rScale + rBias; |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 800 | } |
| 801 | } |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 802 | if (gScale != 1.0 || gBias != 0.0) { |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 803 | GLuint i; |
| 804 | for (i = 0; i < n; i++) { |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 805 | rgba[i][GCOMP] = rgba[i][GCOMP] * gScale + gBias; |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 808 | if (bScale != 1.0 || bBias != 0.0) { |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 809 | GLuint i; |
| 810 | for (i = 0; i < n; i++) { |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 811 | rgba[i][BCOMP] = rgba[i][BCOMP] * bScale + bBias; |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 812 | } |
| 813 | } |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 814 | if (aScale != 1.0 || aBias != 0.0) { |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 815 | GLuint i; |
| 816 | for (i = 0; i < n; i++) { |
| Brian Paul | 45015e4 | 2000-11-28 00:07:51 +0000 | [diff] [blame] | 817 | rgba[i][ACOMP] = rgba[i][ACOMP] * aScale + aBias; |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | |
| 823 | /* |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 824 | * Apply pixel mapping to an array of floating point RGBA pixels. |
| 825 | */ |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 826 | void |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 827 | _mesa_map_rgba( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] ) |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 828 | { |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 829 | const GLfloat rscale = (GLfloat) (ctx->Pixel.MapRtoRsize - 1); |
| 830 | const GLfloat gscale = (GLfloat) (ctx->Pixel.MapGtoGsize - 1); |
| 831 | const GLfloat bscale = (GLfloat) (ctx->Pixel.MapBtoBsize - 1); |
| 832 | const GLfloat ascale = (GLfloat) (ctx->Pixel.MapAtoAsize - 1); |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 833 | const GLfloat *rMap = ctx->Pixel.MapRtoR; |
| 834 | const GLfloat *gMap = ctx->Pixel.MapGtoG; |
| 835 | const GLfloat *bMap = ctx->Pixel.MapBtoB; |
| 836 | const GLfloat *aMap = ctx->Pixel.MapAtoA; |
| 837 | GLuint i; |
| 838 | for (i=0;i<n;i++) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 839 | GLfloat r = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F); |
| 840 | GLfloat g = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F); |
| 841 | GLfloat b = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F); |
| 842 | GLfloat a = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F); |
| 843 | rgba[i][RCOMP] = rMap[IROUND(r * rscale)]; |
| 844 | rgba[i][GCOMP] = gMap[IROUND(g * gscale)]; |
| 845 | rgba[i][BCOMP] = bMap[IROUND(b * bscale)]; |
| 846 | rgba[i][ACOMP] = aMap[IROUND(a * ascale)]; |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /* |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 852 | * Apply the color matrix and post color matrix scaling and biasing. |
| 853 | */ |
| 854 | void |
| 855 | _mesa_transform_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4]) |
| 856 | { |
| Brian Paul | 82b02f0 | 2000-05-07 20:37:40 +0000 | [diff] [blame] | 857 | const GLfloat rs = ctx->Pixel.PostColorMatrixScale[0]; |
| 858 | const GLfloat rb = ctx->Pixel.PostColorMatrixBias[0]; |
| 859 | const GLfloat gs = ctx->Pixel.PostColorMatrixScale[1]; |
| 860 | const GLfloat gb = ctx->Pixel.PostColorMatrixBias[1]; |
| 861 | const GLfloat bs = ctx->Pixel.PostColorMatrixScale[2]; |
| 862 | const GLfloat bb = ctx->Pixel.PostColorMatrixBias[2]; |
| 863 | const GLfloat as = ctx->Pixel.PostColorMatrixScale[3]; |
| 864 | const GLfloat ab = ctx->Pixel.PostColorMatrixBias[3]; |
| Brian Paul | 30f51ae | 2001-12-18 04:06:44 +0000 | [diff] [blame] | 865 | const GLfloat *m = ctx->ColorMatrixStack.Top->m; |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 866 | GLuint i; |
| 867 | for (i = 0; i < n; i++) { |
| 868 | const GLfloat r = rgba[i][RCOMP]; |
| 869 | const GLfloat g = rgba[i][GCOMP]; |
| 870 | const GLfloat b = rgba[i][BCOMP]; |
| 871 | const GLfloat a = rgba[i][ACOMP]; |
| 872 | rgba[i][RCOMP] = (m[0] * r + m[4] * g + m[ 8] * b + m[12] * a) * rs + rb; |
| 873 | rgba[i][GCOMP] = (m[1] * r + m[5] * g + m[ 9] * b + m[13] * a) * gs + gb; |
| 874 | rgba[i][BCOMP] = (m[2] * r + m[6] * g + m[10] * b + m[14] * a) * bs + bb; |
| 875 | rgba[i][ACOMP] = (m[3] * r + m[7] * g + m[11] * b + m[15] * a) * as + ab; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | |
| Brian Paul | 250069d | 2000-04-08 18:57:45 +0000 | [diff] [blame] | 880 | /* |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 881 | * Apply a color table lookup to an array of colors. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 882 | */ |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 883 | void |
| 884 | _mesa_lookup_rgba(const struct gl_color_table *table, |
| 885 | GLuint n, GLfloat rgba[][4]) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 886 | { |
| Brian Paul | 8753b1c | 2001-02-27 16:42:01 +0000 | [diff] [blame] | 887 | if (!table->Table || table->Size == 0) |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 888 | return; |
| 889 | |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 890 | switch (table->Format) { |
| 891 | case GL_INTENSITY: |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 892 | /* replace RGBA with I */ |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 893 | if (!table->FloatTable) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 894 | const GLint max = table->Size - 1; |
| 895 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 896 | const GLchan *lut = (const GLchan *) table->Table; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 897 | GLuint i; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 898 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 899 | GLint j = IROUND(rgba[i][RCOMP] * scale); |
| Brian Paul | 7cac85d | 2003-01-26 14:34:56 +0000 | [diff] [blame] | 900 | GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]); |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 901 | rgba[i][RCOMP] = rgba[i][GCOMP] = |
| 902 | rgba[i][BCOMP] = rgba[i][ACOMP] = c; |
| 903 | } |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 904 | } |
| 905 | else { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 906 | const GLint max = table->Size - 1; |
| 907 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 908 | const GLfloat *lut = (const GLfloat *) table->Table; |
| 909 | GLuint i; |
| 910 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 911 | GLint j = IROUND(rgba[i][RCOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 912 | GLfloat c = lut[CLAMP(j, 0, max)]; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 913 | rgba[i][RCOMP] = rgba[i][GCOMP] = |
| 914 | rgba[i][BCOMP] = rgba[i][ACOMP] = c; |
| 915 | } |
| 916 | } |
| 917 | break; |
| 918 | case GL_LUMINANCE: |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 919 | /* replace RGB with L */ |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 920 | if (!table->FloatTable) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 921 | const GLint max = table->Size - 1; |
| 922 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 923 | const GLchan *lut = (const GLchan *) table->Table; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 924 | GLuint i; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 925 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 926 | GLint j = IROUND(rgba[i][RCOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 927 | GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]); |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 928 | rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; |
| 929 | } |
| 930 | } |
| 931 | else { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 932 | const GLint max = table->Size - 1; |
| 933 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 934 | const GLfloat *lut = (const GLfloat *) table->Table; |
| 935 | GLuint i; |
| 936 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 937 | GLint j = IROUND(rgba[i][RCOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 938 | GLfloat c = lut[CLAMP(j, 0, max)]; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 939 | rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; |
| 940 | } |
| 941 | } |
| 942 | break; |
| 943 | case GL_ALPHA: |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 944 | /* replace A with A */ |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 945 | if (!table->FloatTable) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 946 | const GLint max = table->Size - 1; |
| 947 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 948 | const GLchan *lut = (const GLchan *) table->Table; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 949 | GLuint i; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 950 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 951 | GLint j = IROUND(rgba[i][ACOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 952 | rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]); |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | else { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 956 | const GLint max = table->Size - 1; |
| 957 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 958 | const GLfloat *lut = (const GLfloat *) table->Table; |
| 959 | GLuint i; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 960 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 961 | GLint j = IROUND(rgba[i][ACOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 962 | rgba[i][ACOMP] = lut[CLAMP(j, 0, max)]; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | break; |
| 966 | case GL_LUMINANCE_ALPHA: |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 967 | /* replace RGBA with LLLA */ |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 968 | if (!table->FloatTable) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 969 | const GLint max = table->Size - 1; |
| 970 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 971 | const GLchan *lut = (const GLchan *) table->Table; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 972 | GLuint i; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 973 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 974 | GLint jL = IROUND(rgba[i][RCOMP] * scale); |
| 975 | GLint jA = IROUND(rgba[i][ACOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 976 | GLfloat luminance, alpha; |
| 977 | jL = CLAMP(jL, 0, max); |
| 978 | jA = CLAMP(jA, 0, max); |
| 979 | luminance = CHAN_TO_FLOAT(lut[jL * 2 + 0]); |
| 980 | alpha = CHAN_TO_FLOAT(lut[jA * 2 + 1]); |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 981 | rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; |
| 982 | rgba[i][ACOMP] = alpha;; |
| 983 | } |
| 984 | } |
| 985 | else { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 986 | const GLint max = table->Size - 1; |
| 987 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 988 | const GLfloat *lut = (const GLfloat *) table->Table; |
| 989 | GLuint i; |
| 990 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 991 | GLint jL = IROUND(rgba[i][RCOMP] * scale); |
| 992 | GLint jA = IROUND(rgba[i][ACOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 993 | GLfloat luminance, alpha; |
| 994 | jL = CLAMP(jL, 0, max); |
| 995 | jA = CLAMP(jA, 0, max); |
| 996 | luminance = lut[jL * 2 + 0]; |
| 997 | alpha = lut[jA * 2 + 1]; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 998 | rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; |
| 999 | rgba[i][ACOMP] = alpha;; |
| 1000 | } |
| 1001 | } |
| 1002 | break; |
| 1003 | case GL_RGB: |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1004 | /* replace RGB with RGB */ |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 1005 | if (!table->FloatTable) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1006 | const GLint max = table->Size - 1; |
| 1007 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1008 | const GLchan *lut = (const GLchan *) table->Table; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1009 | GLuint i; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1010 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 1011 | GLint jR = IROUND(rgba[i][RCOMP] * scale); |
| 1012 | GLint jG = IROUND(rgba[i][GCOMP] * scale); |
| 1013 | GLint jB = IROUND(rgba[i][BCOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1014 | jR = CLAMP(jR, 0, max); |
| 1015 | jG = CLAMP(jG, 0, max); |
| 1016 | jB = CLAMP(jB, 0, max); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1017 | rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 3 + 0]); |
| 1018 | rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 3 + 1]); |
| 1019 | rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 3 + 2]); |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | else { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1023 | const GLint max = table->Size - 1; |
| 1024 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1025 | const GLfloat *lut = (const GLfloat *) table->Table; |
| 1026 | GLuint i; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1027 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 1028 | GLint jR = IROUND(rgba[i][RCOMP] * scale); |
| 1029 | GLint jG = IROUND(rgba[i][GCOMP] * scale); |
| 1030 | GLint jB = IROUND(rgba[i][BCOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1031 | jR = CLAMP(jR, 0, max); |
| 1032 | jG = CLAMP(jG, 0, max); |
| 1033 | jB = CLAMP(jB, 0, max); |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1034 | rgba[i][RCOMP] = lut[jR * 3 + 0]; |
| 1035 | rgba[i][GCOMP] = lut[jG * 3 + 1]; |
| 1036 | rgba[i][BCOMP] = lut[jB * 3 + 2]; |
| 1037 | } |
| 1038 | } |
| 1039 | break; |
| 1040 | case GL_RGBA: |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1041 | /* replace RGBA with RGBA */ |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 1042 | if (!table->FloatTable) { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1043 | const GLint max = table->Size - 1; |
| 1044 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1045 | const GLchan *lut = (const GLchan *) table->Table; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1046 | GLuint i; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1047 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 1048 | GLint jR = IROUND(rgba[i][RCOMP] * scale); |
| 1049 | GLint jG = IROUND(rgba[i][GCOMP] * scale); |
| 1050 | GLint jB = IROUND(rgba[i][BCOMP] * scale); |
| 1051 | GLint jA = IROUND(rgba[i][ACOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1052 | jR = CLAMP(jR, 0, max); |
| 1053 | jG = CLAMP(jG, 0, max); |
| 1054 | jB = CLAMP(jB, 0, max); |
| 1055 | jA = CLAMP(jA, 0, max); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1056 | rgba[i][RCOMP] = CHAN_TO_FLOAT(lut[jR * 4 + 0]); |
| 1057 | rgba[i][GCOMP] = CHAN_TO_FLOAT(lut[jG * 4 + 1]); |
| 1058 | rgba[i][BCOMP] = CHAN_TO_FLOAT(lut[jB * 4 + 2]); |
| 1059 | rgba[i][ACOMP] = CHAN_TO_FLOAT(lut[jA * 4 + 3]); |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | else { |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1063 | const GLint max = table->Size - 1; |
| 1064 | const GLfloat scale = (GLfloat) max; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 1065 | const GLfloat *lut = (const GLfloat *) table->Table; |
| 1066 | GLuint i; |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1067 | for (i = 0; i < n; i++) { |
| Brian Paul | 3314330 | 2001-04-10 15:25:45 +0000 | [diff] [blame] | 1068 | GLint jR = IROUND(rgba[i][RCOMP] * scale); |
| 1069 | GLint jG = IROUND(rgba[i][GCOMP] * scale); |
| 1070 | GLint jB = IROUND(rgba[i][BCOMP] * scale); |
| 1071 | GLint jA = IROUND(rgba[i][ACOMP] * scale); |
| Brian Paul | f6e0e92 | 2001-05-23 23:55:01 +0000 | [diff] [blame] | 1072 | jR = CLAMP(jR, 0, max); |
| 1073 | jG = CLAMP(jG, 0, max); |
| 1074 | jB = CLAMP(jB, 0, max); |
| 1075 | jA = CLAMP(jA, 0, max); |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1076 | rgba[i][RCOMP] = lut[jR * 4 + 0]; |
| 1077 | rgba[i][GCOMP] = lut[jG * 4 + 1]; |
| 1078 | rgba[i][BCOMP] = lut[jB * 4 + 2]; |
| 1079 | rgba[i][ACOMP] = lut[jA * 4 + 3]; |
| 1080 | } |
| 1081 | } |
| 1082 | break; |
| 1083 | default: |
| Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 1084 | _mesa_problem(NULL, "Bad format in _mesa_lookup_rgba"); |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1085 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | /* |
| 1092 | * Apply color index shift and offset to an array of pixels. |
| 1093 | */ |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1094 | void |
| 1095 | _mesa_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1096 | { |
| 1097 | GLint shift = ctx->Pixel.IndexShift; |
| 1098 | GLint offset = ctx->Pixel.IndexOffset; |
| 1099 | GLuint i; |
| 1100 | if (shift > 0) { |
| 1101 | for (i=0;i<n;i++) { |
| 1102 | indexes[i] = (indexes[i] << shift) + offset; |
| 1103 | } |
| 1104 | } |
| 1105 | else if (shift < 0) { |
| 1106 | shift = -shift; |
| 1107 | for (i=0;i<n;i++) { |
| 1108 | indexes[i] = (indexes[i] >> shift) + offset; |
| 1109 | } |
| 1110 | } |
| 1111 | else { |
| 1112 | for (i=0;i<n;i++) { |
| 1113 | indexes[i] = indexes[i] + offset; |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | /* |
| 1120 | * Apply color index mapping to color indexes. |
| 1121 | */ |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1122 | void |
| 1123 | _mesa_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1124 | { |
| 1125 | GLuint mask = ctx->Pixel.MapItoIsize - 1; |
| 1126 | GLuint i; |
| 1127 | for (i=0;i<n;i++) { |
| 1128 | index[i] = ctx->Pixel.MapItoI[ index[i] & mask ]; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | /* |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 1134 | * Map color indexes to rgba values. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1135 | */ |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1136 | void |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1137 | _mesa_map_ci_to_rgba_chan( const GLcontext *ctx, GLuint n, |
| 1138 | const GLuint index[], GLchan rgba[][4] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1139 | { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1140 | #if CHAN_BITS == 8 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1141 | GLuint rmask = ctx->Pixel.MapItoRsize - 1; |
| 1142 | GLuint gmask = ctx->Pixel.MapItoGsize - 1; |
| 1143 | GLuint bmask = ctx->Pixel.MapItoBsize - 1; |
| 1144 | GLuint amask = ctx->Pixel.MapItoAsize - 1; |
| 1145 | const GLubyte *rMap = ctx->Pixel.MapItoR8; |
| 1146 | const GLubyte *gMap = ctx->Pixel.MapItoG8; |
| 1147 | const GLubyte *bMap = ctx->Pixel.MapItoB8; |
| 1148 | const GLubyte *aMap = ctx->Pixel.MapItoA8; |
| 1149 | GLuint i; |
| 1150 | for (i=0;i<n;i++) { |
| 1151 | rgba[i][RCOMP] = rMap[index[i] & rmask]; |
| 1152 | rgba[i][GCOMP] = gMap[index[i] & gmask]; |
| 1153 | rgba[i][BCOMP] = bMap[index[i] & bmask]; |
| 1154 | rgba[i][ACOMP] = aMap[index[i] & amask]; |
| 1155 | } |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1156 | #else |
| 1157 | GLuint rmask = ctx->Pixel.MapItoRsize - 1; |
| 1158 | GLuint gmask = ctx->Pixel.MapItoGsize - 1; |
| 1159 | GLuint bmask = ctx->Pixel.MapItoBsize - 1; |
| 1160 | GLuint amask = ctx->Pixel.MapItoAsize - 1; |
| 1161 | const GLfloat *rMap = ctx->Pixel.MapItoR; |
| 1162 | const GLfloat *gMap = ctx->Pixel.MapItoG; |
| 1163 | const GLfloat *bMap = ctx->Pixel.MapItoB; |
| 1164 | const GLfloat *aMap = ctx->Pixel.MapItoA; |
| 1165 | GLuint i; |
| 1166 | for (i=0;i<n;i++) { |
| Brian Paul | 6532db9 | 2001-01-03 15:59:30 +0000 | [diff] [blame] | 1167 | CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], rMap[index[i] & rmask]); |
| 1168 | CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], gMap[index[i] & gmask]); |
| 1169 | CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], bMap[index[i] & bmask]); |
| 1170 | CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], aMap[index[i] & amask]); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1171 | } |
| 1172 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | |
| 1176 | /* |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 1177 | * Map color indexes to float rgba values. |
| 1178 | */ |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1179 | void |
| 1180 | _mesa_map_ci_to_rgba( const GLcontext *ctx, GLuint n, |
| 1181 | const GLuint index[], GLfloat rgba[][4] ) |
| Brian Paul | 3c14ec9 | 1999-10-30 08:20:57 +0000 | [diff] [blame] | 1182 | { |
| 1183 | GLuint rmask = ctx->Pixel.MapItoRsize - 1; |
| 1184 | GLuint gmask = ctx->Pixel.MapItoGsize - 1; |
| 1185 | GLuint bmask = ctx->Pixel.MapItoBsize - 1; |
| 1186 | GLuint amask = ctx->Pixel.MapItoAsize - 1; |
| 1187 | const GLfloat *rMap = ctx->Pixel.MapItoR; |
| 1188 | const GLfloat *gMap = ctx->Pixel.MapItoG; |
| 1189 | const GLfloat *bMap = ctx->Pixel.MapItoB; |
| 1190 | const GLfloat *aMap = ctx->Pixel.MapItoA; |
| 1191 | GLuint i; |
| 1192 | for (i=0;i<n;i++) { |
| 1193 | rgba[i][RCOMP] = rMap[index[i] & rmask]; |
| 1194 | rgba[i][GCOMP] = gMap[index[i] & gmask]; |
| 1195 | rgba[i][BCOMP] = bMap[index[i] & bmask]; |
| 1196 | rgba[i][ACOMP] = aMap[index[i] & amask]; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | /* |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1202 | * Map 8-bit color indexes to rgb values. |
| 1203 | */ |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1204 | void |
| 1205 | _mesa_map_ci8_to_rgba( const GLcontext *ctx, GLuint n, const GLubyte index[], |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1206 | GLchan rgba[][4] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1207 | { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1208 | #if CHAN_BITS == 8 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1209 | GLuint rmask = ctx->Pixel.MapItoRsize - 1; |
| 1210 | GLuint gmask = ctx->Pixel.MapItoGsize - 1; |
| 1211 | GLuint bmask = ctx->Pixel.MapItoBsize - 1; |
| 1212 | GLuint amask = ctx->Pixel.MapItoAsize - 1; |
| 1213 | const GLubyte *rMap = ctx->Pixel.MapItoR8; |
| 1214 | const GLubyte *gMap = ctx->Pixel.MapItoG8; |
| 1215 | const GLubyte *bMap = ctx->Pixel.MapItoB8; |
| 1216 | const GLubyte *aMap = ctx->Pixel.MapItoA8; |
| 1217 | GLuint i; |
| 1218 | for (i=0;i<n;i++) { |
| 1219 | rgba[i][RCOMP] = rMap[index[i] & rmask]; |
| 1220 | rgba[i][GCOMP] = gMap[index[i] & gmask]; |
| 1221 | rgba[i][BCOMP] = bMap[index[i] & bmask]; |
| 1222 | rgba[i][ACOMP] = aMap[index[i] & amask]; |
| 1223 | } |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1224 | #else |
| 1225 | GLuint rmask = ctx->Pixel.MapItoRsize - 1; |
| 1226 | GLuint gmask = ctx->Pixel.MapItoGsize - 1; |
| 1227 | GLuint bmask = ctx->Pixel.MapItoBsize - 1; |
| 1228 | GLuint amask = ctx->Pixel.MapItoAsize - 1; |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1229 | const GLfloat *rMap = ctx->Pixel.MapItoR; |
| 1230 | const GLfloat *gMap = ctx->Pixel.MapItoG; |
| 1231 | const GLfloat *bMap = ctx->Pixel.MapItoB; |
| 1232 | const GLfloat *aMap = ctx->Pixel.MapItoA; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1233 | GLuint i; |
| 1234 | for (i=0;i<n;i++) { |
| Brian Paul | 6532db9 | 2001-01-03 15:59:30 +0000 | [diff] [blame] | 1235 | CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], rMap[index[i] & rmask]); |
| 1236 | CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], gMap[index[i] & gmask]); |
| 1237 | CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], bMap[index[i] & bmask]); |
| 1238 | CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], aMap[index[i] & amask]); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1239 | } |
| 1240 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1244 | void |
| 1245 | _mesa_shift_and_offset_stencil( const GLcontext *ctx, GLuint n, |
| 1246 | GLstencil stencil[] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1247 | { |
| 1248 | GLuint i; |
| 1249 | GLint shift = ctx->Pixel.IndexShift; |
| 1250 | GLint offset = ctx->Pixel.IndexOffset; |
| 1251 | if (shift > 0) { |
| 1252 | for (i=0;i<n;i++) { |
| 1253 | stencil[i] = (stencil[i] << shift) + offset; |
| 1254 | } |
| 1255 | } |
| 1256 | else if (shift < 0) { |
| 1257 | shift = -shift; |
| 1258 | for (i=0;i<n;i++) { |
| 1259 | stencil[i] = (stencil[i] >> shift) + offset; |
| 1260 | } |
| 1261 | } |
| 1262 | else { |
| 1263 | for (i=0;i<n;i++) { |
| 1264 | stencil[i] = stencil[i] + offset; |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | } |
| 1269 | |
| 1270 | |
| Brian Paul | 179870a | 2000-04-12 18:54:48 +0000 | [diff] [blame] | 1271 | void |
| 1272 | _mesa_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1273 | { |
| 1274 | GLuint mask = ctx->Pixel.MapStoSsize - 1; |
| 1275 | GLuint i; |
| 1276 | for (i=0;i<n;i++) { |
| 1277 | stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ]; |
| 1278 | } |
| 1279 | } |
| Brian Paul | 062bc07 | 2000-12-13 00:46:21 +0000 | [diff] [blame] | 1280 | |
| 1281 | |
| 1282 | |
| 1283 | /* |
| 1284 | * This function converts an array of GLchan colors to GLfloat colors. |
| 1285 | * Most importantly, it undoes the non-uniform quantization of pixel |
| 1286 | * values introduced when we convert shallow (< 8 bit) pixel values |
| 1287 | * to GLubytes in the ctx->Driver.ReadRGBASpan() functions. |
| 1288 | * This fixes a number of OpenGL conformance failures when running on |
| 1289 | * 16bpp displays, for example. |
| 1290 | */ |
| 1291 | void |
| 1292 | _mesa_chan_to_float_span(const GLcontext *ctx, GLuint n, |
| 1293 | CONST GLchan rgba[][4], GLfloat rgbaf[][4]) |
| 1294 | { |
| Brian Paul | f431a3f | 2001-07-13 20:07:37 +0000 | [diff] [blame] | 1295 | #if CHAN_TYPE == GL_FLOAT |
| 1296 | MEMCPY(rgbaf, rgba, n * 4 * sizeof(GLfloat)); |
| 1297 | #else |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1298 | const GLuint rShift = CHAN_BITS - ctx->Visual.redBits; |
| 1299 | const GLuint gShift = CHAN_BITS - ctx->Visual.greenBits; |
| 1300 | const GLuint bShift = CHAN_BITS - ctx->Visual.blueBits; |
| Brian Paul | 062bc07 | 2000-12-13 00:46:21 +0000 | [diff] [blame] | 1301 | GLuint aShift; |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 1302 | const GLfloat rScale = 1.0F / (GLfloat) ((1 << ctx->Visual.redBits ) - 1); |
| 1303 | const GLfloat gScale = 1.0F / (GLfloat) ((1 << ctx->Visual.greenBits) - 1); |
| 1304 | const GLfloat bScale = 1.0F / (GLfloat) ((1 << ctx->Visual.blueBits ) - 1); |
| Brian Paul | 062bc07 | 2000-12-13 00:46:21 +0000 | [diff] [blame] | 1305 | GLfloat aScale; |
| 1306 | GLuint i; |
| 1307 | |
| Brian Paul | b6bcae5 | 2001-01-23 23:39:36 +0000 | [diff] [blame] | 1308 | if (ctx->Visual.alphaBits > 0) { |
| 1309 | aShift = CHAN_BITS - ctx->Visual.alphaBits; |
| Karl Schultz | 94a6ec8 | 2001-09-18 16:16:21 +0000 | [diff] [blame] | 1310 | aScale = 1.0F / (GLfloat) ((1 << ctx->Visual.alphaBits) - 1); |
| Brian Paul | 062bc07 | 2000-12-13 00:46:21 +0000 | [diff] [blame] | 1311 | } |
| 1312 | else { |
| 1313 | aShift = 0; |
| 1314 | aScale = 1.0F / CHAN_MAXF; |
| 1315 | } |
| 1316 | |
| 1317 | for (i = 0; i < n; i++) { |
| 1318 | const GLint r = rgba[i][RCOMP] >> rShift; |
| 1319 | const GLint g = rgba[i][GCOMP] >> gShift; |
| 1320 | const GLint b = rgba[i][BCOMP] >> bShift; |
| 1321 | const GLint a = rgba[i][ACOMP] >> aShift; |
| 1322 | rgbaf[i][RCOMP] = (GLfloat) r * rScale; |
| 1323 | rgbaf[i][GCOMP] = (GLfloat) g * gScale; |
| 1324 | rgbaf[i][BCOMP] = (GLfloat) b * bScale; |
| 1325 | rgbaf[i][ACOMP] = (GLfloat) a * aScale; |
| 1326 | } |
| Brian Paul | f431a3f | 2001-07-13 20:07:37 +0000 | [diff] [blame] | 1327 | #endif |
| Brian Paul | 062bc07 | 2000-12-13 00:46:21 +0000 | [diff] [blame] | 1328 | } |