| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
/* KW: Moved these here to remove knowledge of swrast from core mesa. |
| 26 |
* Should probably pull the entire software implementation of these |
| 27 |
* extensions into either swrast or a sister module. |
| 28 |
*/ |
| 29 |
|
| 30 |
#include "s_context.h" |
| 31 |
#include "s_span.h" |
| 32 |
#include "colortab.h" |
| 33 |
#include "convolve.h" |
| 34 |
|
| 35 |
|
| 36 |
void |
| 37 |
_swrast_CopyColorTable( GLcontext *ctx, |
| 38 |
GLenum target, GLenum internalformat, |
| 39 |
GLint x, GLint y, GLsizei width) |
| 40 |
{ |
| 41 |
GLchan data[MAX_WIDTH][4]; |
| 42 |
struct gl_buffer_object *bufferSave; |
| 43 |
|
| 44 |
if (!ctx->ReadBuffer->_ColorReadBuffer) { |
| 45 |
/* no readbuffer - OK */ |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
/* Select buffer to read from */ |
| 50 |
_swrast_use_read_buffer(ctx); |
| 51 |
|
| 52 |
if (width > MAX_WIDTH) |
| 53 |
width = MAX_WIDTH; |
| 54 |
|
| 55 |
/* read the data from framebuffer */ |
| 56 |
_swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer, |
| 57 |
width, x, y, data ); |
| 58 |
|
| 59 |
/* Restore reading from draw buffer (the default) */ |
| 60 |
_swrast_use_draw_buffer(ctx); |
| 61 |
|
| 62 |
/* save PBO binding */ |
| 63 |
bufferSave = ctx->Unpack.BufferObj; |
| 64 |
ctx->Unpack.BufferObj = ctx->Array.NullBufferObj; |
| 65 |
|
| 66 |
_mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data); |
| 67 |
|
| 68 |
/* restore PBO binding */ |
| 69 |
ctx->Unpack.BufferObj = bufferSave; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
void |
| 74 |
_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start, |
| 75 |
GLint x, GLint y, GLsizei width) |
| 76 |
{ |
| 77 |
GLchan data[MAX_WIDTH][4]; |
| 78 |
struct gl_buffer_object *bufferSave; |
| 79 |
|
| 80 |
if (!ctx->ReadBuffer->_ColorReadBuffer) { |
| 81 |
/* no readbuffer - OK */ |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
/* Select buffer to read from */ |
| 86 |
_swrast_use_read_buffer(ctx); |
| 87 |
|
| 88 |
if (width > MAX_WIDTH) |
| 89 |
width = MAX_WIDTH; |
| 90 |
|
| 91 |
/* read the data from framebuffer */ |
| 92 |
_swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer, |
| 93 |
width, x, y, data ); |
| 94 |
|
| 95 |
/* Restore reading from draw buffer (the default) */ |
| 96 |
_swrast_use_draw_buffer(ctx); |
| 97 |
|
| 98 |
/* save PBO binding */ |
| 99 |
bufferSave = ctx->Unpack.BufferObj; |
| 100 |
ctx->Unpack.BufferObj = ctx->Array.NullBufferObj; |
| 101 |
|
| 102 |
_mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data); |
| 103 |
|
| 104 |
/* restore PBO binding */ |
| 105 |
ctx->Unpack.BufferObj = bufferSave; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
void |
| 110 |
_swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target, |
| 111 |
GLenum internalFormat, |
| 112 |
GLint x, GLint y, GLsizei width) |
| 113 |
{ |
| 114 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 115 |
GLchan rgba[MAX_CONVOLUTION_WIDTH][4]; |
| 116 |
struct gl_buffer_object *bufferSave; |
| 117 |
|
| 118 |
if (!ctx->ReadBuffer->_ColorReadBuffer) { |
| 119 |
/* no readbuffer - OK */ |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
/* Select buffer to read from */ |
| 124 |
_swrast_use_read_buffer(ctx); |
| 125 |
|
| 126 |
RENDER_START( swrast, ctx ); |
| 127 |
|
| 128 |
/* read the data from framebuffer */ |
| 129 |
_swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer, |
| 130 |
width, x, y, (GLchan (*)[4]) rgba ); |
| 131 |
|
| 132 |
RENDER_FINISH( swrast, ctx ); |
| 133 |
|
| 134 |
/* Restore reading from draw buffer (the default) */ |
| 135 |
_swrast_use_draw_buffer(ctx); |
| 136 |
|
| 137 |
/* save PBO binding */ |
| 138 |
bufferSave = ctx->Unpack.BufferObj; |
| 139 |
ctx->Unpack.BufferObj = ctx->Array.NullBufferObj; |
| 140 |
|
| 141 |
/* store as convolution filter */ |
| 142 |
_mesa_ConvolutionFilter1D(target, internalFormat, width, |
| 143 |
GL_RGBA, CHAN_TYPE, rgba); |
| 144 |
|
| 145 |
/* restore PBO binding */ |
| 146 |
ctx->Unpack.BufferObj = bufferSave; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
void |
| 151 |
_swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target, |
| 152 |
GLenum internalFormat, |
| 153 |
GLint x, GLint y, GLsizei width, GLsizei height) |
| 154 |
{ |
| 155 |
SWcontext *swrast = SWRAST_CONTEXT(ctx); |
| 156 |
struct gl_pixelstore_attrib packSave; |
| 157 |
GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4]; |
| 158 |
GLint i; |
| 159 |
struct gl_buffer_object *bufferSave; |
| 160 |
|
| 161 |
if (!ctx->ReadBuffer->_ColorReadBuffer) { |
| 162 |
/* no readbuffer - OK */ |
| 163 |
return; |
| 164 |
} |
| 165 |
|
| 166 |
/* Select buffer to read from */ |
| 167 |
_swrast_use_read_buffer(ctx); |
| 168 |
|
| 169 |
RENDER_START(swrast,ctx); |
| 170 |
|
| 171 |
/* read pixels from framebuffer */ |
| 172 |
for (i = 0; i < height; i++) { |
| 173 |
_swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer, |
| 174 |
width, x, y + i, (GLchan (*)[4]) rgba[i] ); |
| 175 |
} |
| 176 |
|
| 177 |
RENDER_FINISH(swrast,ctx); |
| 178 |
|
| 179 |
/* Restore reading from draw buffer (the default) */ |
| 180 |
_swrast_use_draw_buffer(ctx); |
| 181 |
|
| 182 |
/* |
| 183 |
* HACK: save & restore context state so we can store this as a |
| 184 |
* convolution filter via the GL api. Doesn't call any callbacks |
| 185 |
* hanging off ctx->Unpack statechanges. |
| 186 |
*/ |
| 187 |
|
| 188 |
packSave = ctx->Unpack; /* save pixel packing params */ |
| 189 |
|
| 190 |
ctx->Unpack.Alignment = 1; |
| 191 |
ctx->Unpack.RowLength = MAX_CONVOLUTION_WIDTH; |
| 192 |
ctx->Unpack.SkipPixels = 0; |
| 193 |
ctx->Unpack.SkipRows = 0; |
| 194 |
ctx->Unpack.ImageHeight = 0; |
| 195 |
ctx->Unpack.SkipImages = 0; |
| 196 |
ctx->Unpack.SwapBytes = GL_FALSE; |
| 197 |
ctx->Unpack.LsbFirst = GL_FALSE; |
| 198 |
ctx->Unpack.BufferObj = ctx->Array.NullBufferObj; |
| 199 |
ctx->NewState |= _NEW_PACKUNPACK; |
| 200 |
|
| 201 |
/* save PBO binding */ |
| 202 |
bufferSave = ctx->Unpack.BufferObj; |
| 203 |
ctx->Unpack.BufferObj = ctx->Array.NullBufferObj; |
| 204 |
|
| 205 |
_mesa_ConvolutionFilter2D(target, internalFormat, width, height, |
| 206 |
GL_RGBA, CHAN_TYPE, rgba); |
| 207 |
|
| 208 |
/* restore PBO binding */ |
| 209 |
ctx->Unpack.BufferObj = bufferSave; |
| 210 |
|
| 211 |
ctx->Unpack = packSave; /* restore pixel packing params */ |
| 212 |
ctx->NewState |= _NEW_PACKUNPACK; |
| 213 |
} |