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