1 /* $Id: s_imaging.c,v 1.5 2002/04/04 16:53:00 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 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
41 GLchan data
[MAX_WIDTH
][4];
43 /* Select buffer to read from */
44 (*swrast
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
45 ctx
->Pixel
.DriverReadBuffer
);
47 if (width
> MAX_WIDTH
)
50 /* read the data from framebuffer */
51 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
53 /* Restore reading from draw buffer (the default) */
54 (*swrast
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
55 ctx
->Color
.DriverDrawBuffer
);
57 glColorTable(target
, internalformat
, width
, GL_RGBA
, CHAN_TYPE
, data
);
61 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
62 GLint x
, GLint y
, GLsizei width
)
64 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
65 GLchan data
[MAX_WIDTH
][4];
67 /* Select buffer to read from */
68 (*swrast
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
69 ctx
->Pixel
.DriverReadBuffer
);
71 if (width
> MAX_WIDTH
)
74 /* read the data from framebuffer */
75 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
77 /* Restore reading from draw buffer (the default) */
78 (*swrast
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
79 ctx
->Color
.DriverDrawBuffer
);
81 glColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
86 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
87 GLenum internalFormat
,
88 GLint x
, GLint y
, GLsizei width
)
90 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
91 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
93 RENDER_START( swrast
, ctx
);
95 /* read the data from framebuffer */
96 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
,
97 (GLchan (*)[4]) rgba
);
99 RENDER_FINISH( swrast
, 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 RENDER_START(swrast
,ctx
);
119 /* read pixels from framebuffer */
120 for (i
= 0; i
< height
; i
++) {
121 _mesa_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
+ i
,
122 (GLchan (*)[4]) rgba
[i
] );
125 RENDER_FINISH(swrast
,ctx
);
128 * HACK: save & restore context state so we can store this as a
129 * convolution filter via the GL api. Doesn't call any callbacks
130 * hanging off ctx->Unpack statechanges.
133 packSave
= ctx
->Unpack
; /* save pixel packing params */
135 ctx
->Unpack
.Alignment
= 1;
136 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
137 ctx
->Unpack
.SkipPixels
= 0;
138 ctx
->Unpack
.SkipRows
= 0;
139 ctx
->Unpack
.ImageHeight
= 0;
140 ctx
->Unpack
.SkipImages
= 0;
141 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
142 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
143 ctx
->NewState
|= _NEW_PACKUNPACK
;
145 glConvolutionFilter2D(target
, internalFormat
, width
, height
,
146 GL_RGBA
, CHAN_TYPE
, rgba
);
148 ctx
->Unpack
= packSave
; /* restore pixel packing params */
149 ctx
->NewState
|= _NEW_PACKUNPACK
;