2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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 "s_context.h"
37 _swrast_CopyColorTable( GLcontext
*ctx
,
38 GLenum target
, GLenum internalformat
,
39 GLint x
, GLint y
, GLsizei width
)
41 GLchan data
[MAX_WIDTH
][4];
43 /* Select buffer to read from */
44 _swrast_use_read_buffer(ctx
);
46 if (width
> MAX_WIDTH
)
49 /* read the data from framebuffer */
50 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
52 /* Restore reading from draw buffer (the default) */
53 _swrast_use_draw_buffer(ctx
);
55 _mesa_ColorTable(target
, internalformat
, width
, GL_RGBA
, CHAN_TYPE
, data
);
60 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
61 GLint x
, GLint y
, GLsizei width
)
63 GLchan data
[MAX_WIDTH
][4];
65 /* Select buffer to read from */
66 _swrast_use_read_buffer(ctx
);
68 if (width
> MAX_WIDTH
)
71 /* read the data from framebuffer */
72 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
74 /* Restore reading from draw buffer (the default) */
75 _swrast_use_draw_buffer(ctx
);
77 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
82 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
83 GLenum internalFormat
,
84 GLint x
, GLint y
, GLsizei width
)
86 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
87 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
89 /* Select buffer to read from */
90 _swrast_use_read_buffer(ctx
);
92 RENDER_START( swrast
, ctx
);
94 /* read the data from framebuffer */
95 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
,
96 (GLchan (*)[4]) rgba
);
98 RENDER_FINISH( swrast
, ctx
);
100 /* Restore reading from draw buffer (the default) */
101 _swrast_use_draw_buffer(ctx
);
103 /* store as convolution filter */
104 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
105 GL_RGBA
, CHAN_TYPE
, rgba
);
110 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
111 GLenum internalFormat
,
112 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
114 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
115 struct gl_pixelstore_attrib packSave
;
116 GLchan rgba
[MAX_CONVOLUTION_HEIGHT
][MAX_CONVOLUTION_WIDTH
][4];
119 /* Select buffer to read from */
120 _swrast_use_read_buffer(ctx
);
122 RENDER_START(swrast
,ctx
);
124 /* read pixels from framebuffer */
125 for (i
= 0; i
< height
; i
++) {
126 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
+ i
,
127 (GLchan (*)[4]) rgba
[i
] );
130 RENDER_FINISH(swrast
,ctx
);
132 /* Restore reading from draw buffer (the default) */
133 _swrast_use_draw_buffer(ctx
);
136 * HACK: save & restore context state so we can store this as a
137 * convolution filter via the GL api. Doesn't call any callbacks
138 * hanging off ctx->Unpack statechanges.
141 packSave
= ctx
->Unpack
; /* save pixel packing params */
143 ctx
->Unpack
.Alignment
= 1;
144 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
145 ctx
->Unpack
.SkipPixels
= 0;
146 ctx
->Unpack
.SkipRows
= 0;
147 ctx
->Unpack
.ImageHeight
= 0;
148 ctx
->Unpack
.SkipImages
= 0;
149 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
150 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
151 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
152 ctx
->NewState
|= _NEW_PACKUNPACK
;
154 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
155 GL_RGBA
, CHAN_TYPE
, rgba
);
157 ctx
->Unpack
= packSave
; /* restore pixel packing params */
158 ctx
->NewState
|= _NEW_PACKUNPACK
;