2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
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.
30 #include "main/glheader.h"
31 #include "main/colortab.h"
32 #include "main/convolve.h"
33 #include "s_context.h"
37 #if FEATURE_colortable
41 _swrast_CopyColorTable( GLcontext *ctx,
42 GLenum target, GLenum internalformat,
43 GLint x, GLint y, GLsizei width)
45 GLchan data[MAX_WIDTH][4];
46 struct gl_buffer_object *bufferSave;
48 if (!ctx->ReadBuffer->_ColorReadBuffer) {
49 /* no readbuffer - OK */
53 if (width > MAX_WIDTH)
56 swrast_render_start(ctx);
58 /* read the data from framebuffer */
59 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
60 width, x, y, CHAN_TYPE, data );
62 swrast_render_finish(ctx);
64 /* save PBO binding */
65 bufferSave = ctx->Unpack.BufferObj;
66 ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
68 _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
70 /* restore PBO binding */
71 ctx->Unpack.BufferObj = bufferSave;
76 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
77 GLint x, GLint y, GLsizei width)
79 GLchan data[MAX_WIDTH][4];
80 struct gl_buffer_object *bufferSave;
82 if (!ctx->ReadBuffer->_ColorReadBuffer) {
83 /* no readbuffer - OK */
87 if (width > MAX_WIDTH)
90 swrast_render_start(ctx);
92 /* read the data from framebuffer */
93 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
94 width, x, y, CHAN_TYPE, data );
96 swrast_render_finish(ctx);
98 /* save PBO binding */
99 bufferSave = ctx->Unpack.BufferObj;
100 ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
102 _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
104 /* restore PBO binding */
105 ctx->Unpack.BufferObj = bufferSave;
109 #endif /* FEATURE_colortable */
116 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
117 GLenum internalFormat,
118 GLint x, GLint y, GLsizei width)
120 GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
121 struct gl_buffer_object *bufferSave;
123 if (!ctx->ReadBuffer->_ColorReadBuffer) {
124 /* no readbuffer - OK */
128 swrast_render_start(ctx);
130 /* read the data from framebuffer */
131 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
132 width, x, y, CHAN_TYPE, rgba );
134 swrast_render_finish(ctx);
136 /* save PBO binding */
137 bufferSave = ctx->Unpack.BufferObj;
138 ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
140 /* store as convolution filter */
141 _mesa_ConvolutionFilter1D(target, internalFormat, width,
142 GL_RGBA, CHAN_TYPE, rgba);
144 /* restore PBO binding */
145 ctx->Unpack.BufferObj = bufferSave;
150 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
151 GLenum internalFormat,
152 GLint x, GLint y, GLsizei width, GLsizei height)
154 struct gl_pixelstore_attrib packSave;
155 GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
157 struct gl_buffer_object *bufferSave;
159 if (!ctx->ReadBuffer->_ColorReadBuffer) {
160 /* no readbuffer - OK */
164 swrast_render_start(ctx);
166 /* read pixels from framebuffer */
167 for (i = 0; i < height; i++) {
168 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
169 width, x, y + i, CHAN_TYPE, rgba[i] );
172 swrast_render_finish(ctx);
175 * HACK: save & restore context state so we can store this as a
176 * convolution filter via the GL api. Doesn't call any callbacks
177 * hanging off ctx->Unpack statechanges.
180 packSave = ctx->Unpack; /* save pixel packing params */
182 ctx->Unpack.Alignment = 1;
183 ctx->Unpack.RowLength = MAX_CONVOLUTION_WIDTH;
184 ctx->Unpack.SkipPixels = 0;
185 ctx->Unpack.SkipRows = 0;
186 ctx->Unpack.ImageHeight = 0;
187 ctx->Unpack.SkipImages = 0;
188 ctx->Unpack.SwapBytes = GL_FALSE;
189 ctx->Unpack.LsbFirst = GL_FALSE;
190 ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
191 ctx->NewState |= _NEW_PACKUNPACK;
193 /* save PBO binding */
194 bufferSave = ctx->Unpack.BufferObj;
195 ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
197 _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
198 GL_RGBA, CHAN_TYPE, rgba);
200 /* restore PBO binding */
201 ctx->Unpack.BufferObj = bufferSave;
203 ctx->Unpack = packSave; /* restore pixel packing params */
204 ctx->NewState |= _NEW_PACKUNPACK;
208 #endif /* FEATURE_convolve */