Subversion Repositories shark

Rev

Rev 57 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
57 pj 1
/* $Id: s_imaging.c,v 1.1 2003-02-28 11:49:42 pj 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
   GLchan data[MAX_WIDTH][4];
41
 
42
   /* Select buffer to read from */
43
   _swrast_use_read_buffer(ctx);
44
 
45
   if (width > MAX_WIDTH)
46
      width = MAX_WIDTH;
47
 
48
   /* read the data from framebuffer */
49
   _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
50
 
51
   /* Restore reading from draw buffer (the default) */
52
   _swrast_use_draw_buffer(ctx);
53
 
54
   glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
55
}
56
 
57
void
58
_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
59
                           GLint x, GLint y, GLsizei width)
60
{
61
   GLchan data[MAX_WIDTH][4];
62
 
63
   /* Select buffer to read from */
64
   _swrast_use_read_buffer(ctx);
65
 
66
   if (width > MAX_WIDTH)
67
      width = MAX_WIDTH;
68
 
69
   /* read the data from framebuffer */
70
   _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
71
 
72
   /* Restore reading from draw buffer (the default) */
73
   _swrast_use_draw_buffer(ctx);
74
 
75
   glColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
76
}
77
 
78
 
79
void
80
_swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
81
                                GLenum internalFormat,
82
                                GLint x, GLint y, GLsizei width)
83
{
84
   SWcontext *swrast = SWRAST_CONTEXT(ctx);
85
   GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
86
 
87
   /* Select buffer to read from */
88
   _swrast_use_read_buffer(ctx);
89
 
90
   RENDER_START( swrast, ctx );
91
 
92
   /* read the data from framebuffer */
93
   _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y,
94
                                (GLchan (*)[4]) rgba );
95
 
96
   RENDER_FINISH( swrast, ctx );
97
 
98
   /* Restore reading from draw buffer (the default) */
99
   _swrast_use_draw_buffer(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
   /* Select buffer to read from */
118
   _swrast_use_read_buffer(ctx);
119
 
120
   RENDER_START(swrast,ctx);
121
 
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] );
126
   }
127
 
128
   RENDER_FINISH(swrast,ctx);
129
 
130
   /* Restore reading from draw buffer (the default) */
131
   _swrast_use_draw_buffer(ctx);
132
 
133
   /*
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.
137
    */
138
 
139
   packSave = ctx->Unpack;  /* save pixel packing params */
140
 
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;
150
 
151
   glConvolutionFilter2D(target, internalFormat, width, height,
152
                         GL_RGBA, CHAN_TYPE, rgba);
153
 
154
   ctx->Unpack = packSave;  /* restore pixel packing params */
155
   ctx->NewState |= _NEW_PACKUNPACK;
156
}