blending fixes for CHAN_TYPE==GL_FLOAT (Gerk Huisma)
[mesa.git] / src / mesa / swrast / s_imaging.c
1 /* $Id: s_imaging.c,v 1.5 2002/04/04 16:53:00 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
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.
30 */
31
32 #include "s_context.h"
33 #include "s_span.h"
34
35 void
36 _swrast_CopyColorTable( GLcontext *ctx,
37 GLenum target, GLenum internalformat,
38 GLint x, GLint y, GLsizei width)
39 {
40 SWcontext *swrast = SWRAST_CONTEXT(ctx);
41 GLchan data[MAX_WIDTH][4];
42
43 /* Select buffer to read from */
44 (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
45 ctx->Pixel.DriverReadBuffer );
46
47 if (width > MAX_WIDTH)
48 width = MAX_WIDTH;
49
50 /* read the data from framebuffer */
51 _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
52
53 /* Restore reading from draw buffer (the default) */
54 (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
55 ctx->Color.DriverDrawBuffer );
56
57 glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
58 }
59
60 void
61 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
62 GLint x, GLint y, GLsizei width)
63 {
64 SWcontext *swrast = SWRAST_CONTEXT(ctx);
65 GLchan data[MAX_WIDTH][4];
66
67 /* Select buffer to read from */
68 (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
69 ctx->Pixel.DriverReadBuffer );
70
71 if (width > MAX_WIDTH)
72 width = MAX_WIDTH;
73
74 /* read the data from framebuffer */
75 _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
76
77 /* Restore reading from draw buffer (the default) */
78 (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
79 ctx->Color.DriverDrawBuffer );
80
81 glColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
82 }
83
84
85 void
86 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
87 GLenum internalFormat,
88 GLint x, GLint y, GLsizei width)
89 {
90 SWcontext *swrast = SWRAST_CONTEXT(ctx);
91 GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
92
93 RENDER_START( swrast, ctx );
94
95 /* read the data from framebuffer */
96 _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y,
97 (GLchan (*)[4]) rgba );
98
99 RENDER_FINISH( swrast, ctx );
100
101 /* store as convolution filter */
102 glConvolutionFilter1D(target, internalFormat, width,
103 GL_RGBA, CHAN_TYPE, rgba);
104 }
105
106
107 void
108 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
109 GLenum internalFormat,
110 GLint x, GLint y, GLsizei width, GLsizei height)
111 {
112 SWcontext *swrast = SWRAST_CONTEXT(ctx);
113 struct gl_pixelstore_attrib packSave;
114 GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
115 GLint i;
116
117 RENDER_START(swrast,ctx);
118
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] );
123 }
124
125 RENDER_FINISH(swrast,ctx);
126
127 /*
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.
131 */
132
133 packSave = ctx->Unpack; /* save pixel packing params */
134
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;
144
145 glConvolutionFilter2D(target, internalFormat, width, height,
146 GL_RGBA, CHAN_TYPE, rgba);
147
148 ctx->Unpack = packSave; /* restore pixel packing params */
149 ctx->NewState |= _NEW_PACKUNPACK;
150 }