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