OSDN Git Service

mesa/swrast: Respect mfeatures.h.
[android-x86/external-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 "main/glheader.h"
31 #include "main/colortab.h"
32 #include "main/convolve.h"
33 #include "s_context.h"
34 #include "s_span.h"
35
36
37 #if FEATURE_colortable
38
39
40 void
41 _swrast_CopyColorTable( GLcontext *ctx, 
42                         GLenum target, GLenum internalformat,
43                         GLint x, GLint y, GLsizei width)
44 {
45    GLchan data[MAX_WIDTH][4];
46    struct gl_buffer_object *bufferSave;
47
48    if (!ctx->ReadBuffer->_ColorReadBuffer) {
49       /* no readbuffer - OK */
50       return;
51    }
52
53    if (width > MAX_WIDTH)
54       width = MAX_WIDTH;
55
56    swrast_render_start(ctx);
57
58    /* read the data from framebuffer */
59    _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
60                            width, x, y, CHAN_TYPE, data );
61
62    swrast_render_finish(ctx);
63
64    /* save PBO binding */
65    bufferSave = ctx->Unpack.BufferObj;
66    ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
67
68    _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
69
70    /* restore PBO binding */
71    ctx->Unpack.BufferObj = bufferSave;
72 }
73
74
75 void
76 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
77                            GLint x, GLint y, GLsizei width)
78 {
79    GLchan data[MAX_WIDTH][4];
80    struct gl_buffer_object *bufferSave;
81
82    if (!ctx->ReadBuffer->_ColorReadBuffer) {
83       /* no readbuffer - OK */
84       return;
85    }
86
87    if (width > MAX_WIDTH)
88       width = MAX_WIDTH;
89
90    swrast_render_start(ctx);
91
92    /* read the data from framebuffer */
93    _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
94                            width, x, y, CHAN_TYPE, data );
95
96    swrast_render_finish(ctx);
97
98    /* save PBO binding */
99    bufferSave = ctx->Unpack.BufferObj;
100    ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
101
102    _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
103
104    /* restore PBO binding */
105    ctx->Unpack.BufferObj = bufferSave;
106 }
107
108
109 #endif /* FEATURE_colortable */
110
111
112 #if FEATURE_convolve
113
114
115 void
116 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target, 
117                                 GLenum internalFormat, 
118                                 GLint x, GLint y, GLsizei width)
119 {
120    GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
121    struct gl_buffer_object *bufferSave;
122
123    if (!ctx->ReadBuffer->_ColorReadBuffer) {
124       /* no readbuffer - OK */
125       return;
126    }
127
128    swrast_render_start(ctx);
129
130    /* read the data from framebuffer */
131    _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
132                            width, x, y, CHAN_TYPE, rgba );
133    
134    swrast_render_finish(ctx);
135
136    /* save PBO binding */
137    bufferSave = ctx->Unpack.BufferObj;
138    ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
139
140    /* store as convolution filter */
141    _mesa_ConvolutionFilter1D(target, internalFormat, width,
142                              GL_RGBA, CHAN_TYPE, rgba);
143
144    /* restore PBO binding */
145    ctx->Unpack.BufferObj = bufferSave;
146 }
147
148
149 void
150 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target, 
151                                 GLenum internalFormat, 
152                                 GLint x, GLint y, GLsizei width, GLsizei height)
153 {
154    struct gl_pixelstore_attrib packSave;
155    GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
156    GLint i;
157    struct gl_buffer_object *bufferSave;
158
159    if (!ctx->ReadBuffer->_ColorReadBuffer) {
160       /* no readbuffer - OK */
161       return;
162    }
163
164    swrast_render_start(ctx);
165    
166    /* read pixels from framebuffer */
167    for (i = 0; i < height; i++) {
168       _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
169                               width, x, y + i, CHAN_TYPE, rgba[i] );
170    }
171
172    swrast_render_finish(ctx);
173
174    /*
175     * HACK: save & restore context state so we can store this as a
176     * convolution filter via the GL api.  Doesn't call any callbacks
177     * hanging off ctx->Unpack statechanges.
178     */
179
180    packSave = ctx->Unpack;  /* save pixel packing params */
181
182    ctx->Unpack.Alignment = 1;
183    ctx->Unpack.RowLength = MAX_CONVOLUTION_WIDTH;
184    ctx->Unpack.SkipPixels = 0;
185    ctx->Unpack.SkipRows = 0;
186    ctx->Unpack.ImageHeight = 0;
187    ctx->Unpack.SkipImages = 0;
188    ctx->Unpack.SwapBytes = GL_FALSE;
189    ctx->Unpack.LsbFirst = GL_FALSE;
190    ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
191    ctx->NewState |= _NEW_PACKUNPACK;
192
193    /* save PBO binding */
194    bufferSave = ctx->Unpack.BufferObj;
195    ctx->Unpack.BufferObj = ctx->Shared->NullBufferObj;
196
197    _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
198                              GL_RGBA, CHAN_TYPE, rgba);
199
200    /* restore PBO binding */
201    ctx->Unpack.BufferObj = bufferSave;
202
203    ctx->Unpack = packSave;  /* restore pixel packing params */
204    ctx->NewState |= _NEW_PACKUNPACK; 
205 }
206
207
208 #endif /* FEATURE_convolve */