1 /* $Id: s_imaging.c,v 1.6 2002/07/09 01:22:52 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 /* KW: Moved these here to remove knowledge of swrast from core mesa.
28 * Should probably pull the entire software implementation of these
29 * extensions into either swrast or a sister module.
32 #include "s_context.h"
36 _swrast_CopyColorTable( GLcontext
*ctx
,
37 GLenum target
, GLenum internalformat
,
38 GLint x
, GLint y
, GLsizei width
)
40 GLchan data
[MAX_WIDTH
][4];
42 /* Select buffer to read from */
43 _swrast_use_read_buffer(ctx
);
45 if (width
> MAX_WIDTH
)
48 /* read the data from framebuffer */
49 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
51 /* Restore reading from draw buffer (the default) */
52 _swrast_use_draw_buffer(ctx
);
54 glColorTable(target
, internalformat
, width
, GL_RGBA
, CHAN_TYPE
, data
);
58 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
59 GLint x
, GLint y
, GLsizei width
)
61 GLchan data
[MAX_WIDTH
][4];
63 /* Select buffer to read from */
64 _swrast_use_read_buffer(ctx
);
66 if (width
> MAX_WIDTH
)
69 /* read the data from framebuffer */
70 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
72 /* Restore reading from draw buffer (the default) */
73 _swrast_use_draw_buffer(ctx
);
75 glColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
80 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
81 GLenum internalFormat
,
82 GLint x
, GLint y
, GLsizei width
)
84 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
85 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
87 /* Select buffer to read from */
88 _swrast_use_read_buffer(ctx
);
90 RENDER_START( swrast
, ctx
);
92 /* read the data from framebuffer */
93 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
,
94 (GLchan (*)[4]) rgba
);
96 RENDER_FINISH( swrast
, ctx
);
98 /* Restore reading from draw buffer (the default) */
99 _swrast_use_draw_buffer(ctx
);
101 /* store as convolution filter */
102 glConvolutionFilter1D(target
, internalFormat
, width
,
103 GL_RGBA
, CHAN_TYPE
, rgba
);
108 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
109 GLenum internalFormat
,
110 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
112 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
113 struct gl_pixelstore_attrib packSave
;
114 GLchan rgba
[MAX_CONVOLUTION_HEIGHT
][MAX_CONVOLUTION_WIDTH
][4];
117 /* Select buffer to read from */
118 _swrast_use_read_buffer(ctx
);
120 RENDER_START(swrast
,ctx
);
122 /* read pixels from framebuffer */
123 for (i
= 0; i
< height
; i
++) {
124 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
+ i
,
125 (GLchan (*)[4]) rgba
[i
] );
128 RENDER_FINISH(swrast
,ctx
);
130 /* Restore reading from draw buffer (the default) */
131 _swrast_use_draw_buffer(ctx
);
134 * HACK: save & restore context state so we can store this as a
135 * convolution filter via the GL api. Doesn't call any callbacks
136 * hanging off ctx->Unpack statechanges.
139 packSave
= ctx
->Unpack
; /* save pixel packing params */
141 ctx
->Unpack
.Alignment
= 1;
142 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
143 ctx
->Unpack
.SkipPixels
= 0;
144 ctx
->Unpack
.SkipRows
= 0;
145 ctx
->Unpack
.ImageHeight
= 0;
146 ctx
->Unpack
.SkipImages
= 0;
147 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
148 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
149 ctx
->NewState
|= _NEW_PACKUNPACK
;
151 glConvolutionFilter2D(target
, internalFormat
, width
, height
,
152 GL_RGBA
, CHAN_TYPE
, rgba
);
154 ctx
->Unpack
= packSave
; /* restore pixel packing params */
155 ctx
->NewState
|= _NEW_PACKUNPACK
;