remove unused vars
[mesa.git] / src / mesa / swrast / s_imaging.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 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 if (width > MAX_WIDTH)
50 width = MAX_WIDTH;
51
52 /* read the data from framebuffer */
53 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
54 width, x, y, data );
55
56 /* save PBO binding */
57 bufferSave = ctx->Unpack.BufferObj;
58 ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
59
60 _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
61
62 /* restore PBO binding */
63 ctx->Unpack.BufferObj = bufferSave;
64 }
65
66
67 void
68 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
69 GLint x, GLint y, GLsizei width)
70 {
71 GLchan data[MAX_WIDTH][4];
72 struct gl_buffer_object *bufferSave;
73
74 if (!ctx->ReadBuffer->_ColorReadBuffer) {
75 /* no readbuffer - OK */
76 return;
77 }
78
79 if (width > MAX_WIDTH)
80 width = MAX_WIDTH;
81
82 /* read the data from framebuffer */
83 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
84 width, x, y, data );
85
86 /* save PBO binding */
87 bufferSave = ctx->Unpack.BufferObj;
88 ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
89
90 _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
91
92 /* restore PBO binding */
93 ctx->Unpack.BufferObj = bufferSave;
94 }
95
96
97 void
98 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
99 GLenum internalFormat,
100 GLint x, GLint y, GLsizei width)
101 {
102 SWcontext *swrast = SWRAST_CONTEXT(ctx);
103 GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
104 struct gl_buffer_object *bufferSave;
105
106 if (!ctx->ReadBuffer->_ColorReadBuffer) {
107 /* no readbuffer - OK */
108 return;
109 }
110
111 RENDER_START( swrast, ctx );
112
113 /* read the data from framebuffer */
114 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
115 width, x, y, (GLchan (*)[4]) rgba );
116
117 RENDER_FINISH( swrast, ctx );
118
119 /* save PBO binding */
120 bufferSave = ctx->Unpack.BufferObj;
121 ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
122
123 /* store as convolution filter */
124 _mesa_ConvolutionFilter1D(target, internalFormat, width,
125 GL_RGBA, CHAN_TYPE, rgba);
126
127 /* restore PBO binding */
128 ctx->Unpack.BufferObj = bufferSave;
129 }
130
131
132 void
133 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
134 GLenum internalFormat,
135 GLint x, GLint y, GLsizei width, GLsizei height)
136 {
137 SWcontext *swrast = SWRAST_CONTEXT(ctx);
138 struct gl_pixelstore_attrib packSave;
139 GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
140 GLint i;
141 struct gl_buffer_object *bufferSave;
142
143 if (!ctx->ReadBuffer->_ColorReadBuffer) {
144 /* no readbuffer - OK */
145 return;
146 }
147
148 RENDER_START(swrast,ctx);
149
150 /* read pixels from framebuffer */
151 for (i = 0; i < height; i++) {
152 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
153 width, x, y + i, (GLchan (*)[4]) rgba[i] );
154 }
155
156 RENDER_FINISH(swrast,ctx);
157
158 /*
159 * HACK: save & restore context state so we can store this as a
160 * convolution filter via the GL api. Doesn't call any callbacks
161 * hanging off ctx->Unpack statechanges.
162 */
163
164 packSave = ctx->Unpack; /* save pixel packing params */
165
166 ctx->Unpack.Alignment = 1;
167 ctx->Unpack.RowLength = MAX_CONVOLUTION_WIDTH;
168 ctx->Unpack.SkipPixels = 0;
169 ctx->Unpack.SkipRows = 0;
170 ctx->Unpack.ImageHeight = 0;
171 ctx->Unpack.SkipImages = 0;
172 ctx->Unpack.SwapBytes = GL_FALSE;
173 ctx->Unpack.LsbFirst = GL_FALSE;
174 ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
175 ctx->NewState |= _NEW_PACKUNPACK;
176
177 /* save PBO binding */
178 bufferSave = ctx->Unpack.BufferObj;
179 ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
180
181 _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
182 GL_RGBA, CHAN_TYPE, rgba);
183
184 /* restore PBO binding */
185 ctx->Unpack.BufferObj = bufferSave;
186
187 ctx->Unpack = packSave; /* restore pixel packing params */
188 ctx->NewState |= _NEW_PACKUNPACK;
189 }