1 /* $Id: convolve.c,v 1.23 2001/03/19 02:25:35 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
29 * Image convolution functions.
31 * Notes: filter kernel elements are indexed by <n> and <m> as in
46 #include "swrast/s_span.h" /* XXX SWRAST hack */
51 * Given an internalFormat token passed to glConvolutionFilter
52 * or glSeparableFilter, return the corresponding base format.
53 * Return -1 if invalid token.
56 base_filter_format( GLenum format
)
71 case GL_LUMINANCE_ALPHA
:
72 case GL_LUMINANCE4_ALPHA4
:
73 case GL_LUMINANCE6_ALPHA2
:
74 case GL_LUMINANCE8_ALPHA8
:
75 case GL_LUMINANCE12_ALPHA4
:
76 case GL_LUMINANCE12_ALPHA12
:
77 case GL_LUMINANCE16_ALPHA16
:
78 return GL_LUMINANCE_ALPHA
;
105 return -1; /* error */
111 _mesa_ConvolutionFilter1D(GLenum target
, GLenum internalFormat
, GLsizei width
, GLenum format
, GLenum type
, const GLvoid
*image
)
114 GET_CURRENT_CONTEXT(ctx
);
115 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
117 if (target
!= GL_CONVOLUTION_1D
) {
118 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter1D(target)");
122 baseFormat
= base_filter_format(internalFormat
);
123 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
124 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter1D(internalFormat)");
128 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
129 _mesa_error(ctx
, GL_INVALID_VALUE
, "glConvolutionFilter1D(width)");
133 if (!_mesa_is_legal_format_and_type(format
, type
)) {
134 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glConvolutionFilter1D(format or type)");
138 if (format
== GL_COLOR_INDEX
||
139 format
== GL_STENCIL_INDEX
||
140 format
== GL_DEPTH_COMPONENT
||
141 format
== GL_INTENSITY
||
143 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter1D(format or type)");
147 ctx
->Convolution1D
.Format
= format
;
148 ctx
->Convolution1D
.InternalFormat
= internalFormat
;
149 ctx
->Convolution1D
.Width
= width
;
150 ctx
->Convolution1D
.Height
= 1;
152 /* unpack filter image */
153 _mesa_unpack_float_color_span(ctx
, width
, GL_RGBA
,
154 ctx
->Convolution1D
.Filter
,
155 format
, type
, image
, &ctx
->Unpack
,
158 /* apply scale and bias */
160 const GLfloat
*scale
= ctx
->Pixel
.ConvolutionFilterScale
[0];
161 const GLfloat
*bias
= ctx
->Pixel
.ConvolutionFilterBias
[0];
163 for (i
= 0; i
< width
; i
++) {
164 GLfloat r
= ctx
->Convolution1D
.Filter
[i
* 4 + 0];
165 GLfloat g
= ctx
->Convolution1D
.Filter
[i
* 4 + 1];
166 GLfloat b
= ctx
->Convolution1D
.Filter
[i
* 4 + 2];
167 GLfloat a
= ctx
->Convolution1D
.Filter
[i
* 4 + 3];
168 r
= r
* scale
[0] + bias
[0];
169 g
= g
* scale
[1] + bias
[1];
170 b
= b
* scale
[2] + bias
[2];
171 a
= a
* scale
[3] + bias
[3];
172 ctx
->Convolution1D
.Filter
[i
* 4 + 0] = r
;
173 ctx
->Convolution1D
.Filter
[i
* 4 + 1] = g
;
174 ctx
->Convolution1D
.Filter
[i
* 4 + 2] = b
;
175 ctx
->Convolution1D
.Filter
[i
* 4 + 3] = a
;
179 ctx
->NewState
|= _NEW_PIXEL
;
184 _mesa_ConvolutionFilter2D(GLenum target
, GLenum internalFormat
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, const GLvoid
*image
)
188 GET_CURRENT_CONTEXT(ctx
);
189 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
191 if (target
!= GL_CONVOLUTION_2D
) {
192 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter2D(target)");
196 baseFormat
= base_filter_format(internalFormat
);
197 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
198 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter2D(internalFormat)");
202 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
203 _mesa_error(ctx
, GL_INVALID_VALUE
, "glConvolutionFilter2D(width)");
206 if (height
< 0 || height
> MAX_CONVOLUTION_HEIGHT
) {
207 _mesa_error(ctx
, GL_INVALID_VALUE
, "glConvolutionFilter2D(height)");
211 if (!_mesa_is_legal_format_and_type(format
, type
)) {
212 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glConvolutionFilter2D(format or type)");
215 if (format
== GL_COLOR_INDEX
||
216 format
== GL_STENCIL_INDEX
||
217 format
== GL_DEPTH_COMPONENT
||
218 format
== GL_INTENSITY
||
220 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter2D(format or type)");
224 components
= _mesa_components_in_format(format
);
225 assert(components
> 0); /* this should have been caught earlier */
227 ctx
->Convolution2D
.Format
= format
;
228 ctx
->Convolution2D
.InternalFormat
= internalFormat
;
229 ctx
->Convolution2D
.Width
= width
;
230 ctx
->Convolution2D
.Height
= height
;
232 /* Unpack filter image. We always store filters in RGBA format. */
233 for (i
= 0; i
< height
; i
++) {
234 const GLvoid
*src
= _mesa_image_address(&ctx
->Unpack
, image
, width
,
235 height
, format
, type
, 0, i
, 0);
236 GLfloat
*dst
= ctx
->Convolution2D
.Filter
+ i
* width
* 4;
237 _mesa_unpack_float_color_span(ctx
, width
, GL_RGBA
, dst
,
238 format
, type
, src
, &ctx
->Unpack
,
242 /* apply scale and bias */
244 const GLfloat
*scale
= ctx
->Pixel
.ConvolutionFilterScale
[1];
245 const GLfloat
*bias
= ctx
->Pixel
.ConvolutionFilterBias
[1];
246 for (i
= 0; i
< width
* height
* 4; i
++) {
247 GLfloat r
= ctx
->Convolution2D
.Filter
[i
* 4 + 0];
248 GLfloat g
= ctx
->Convolution2D
.Filter
[i
* 4 + 1];
249 GLfloat b
= ctx
->Convolution2D
.Filter
[i
* 4 + 2];
250 GLfloat a
= ctx
->Convolution2D
.Filter
[i
* 4 + 3];
251 r
= r
* scale
[0] + bias
[0];
252 g
= g
* scale
[1] + bias
[1];
253 b
= b
* scale
[2] + bias
[2];
254 a
= a
* scale
[3] + bias
[3];
255 ctx
->Convolution2D
.Filter
[i
* 4 + 0] = r
;
256 ctx
->Convolution2D
.Filter
[i
* 4 + 1] = g
;
257 ctx
->Convolution2D
.Filter
[i
* 4 + 2] = b
;
258 ctx
->Convolution2D
.Filter
[i
* 4 + 3] = a
;
262 ctx
->NewState
|= _NEW_PIXEL
;
267 _mesa_ConvolutionParameterf(GLenum target
, GLenum pname
, GLfloat param
)
269 GET_CURRENT_CONTEXT(ctx
);
271 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
274 case GL_CONVOLUTION_1D
:
277 case GL_CONVOLUTION_2D
:
280 case GL_SEPARABLE_2D
:
284 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterf(target)");
289 case GL_CONVOLUTION_BORDER_MODE
:
290 if (param
== (GLfloat
) GL_REDUCE
||
291 param
== (GLfloat
) GL_CONSTANT_BORDER
||
292 param
== (GLfloat
) GL_REPLICATE_BORDER
) {
293 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) param
;
296 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterf(params)");
301 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterf(pname)");
305 ctx
->NewState
|= _NEW_PIXEL
;
310 _mesa_ConvolutionParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
312 GET_CURRENT_CONTEXT(ctx
);
313 struct gl_convolution_attrib
*conv
;
315 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
318 case GL_CONVOLUTION_1D
:
320 conv
= &ctx
->Convolution1D
;
322 case GL_CONVOLUTION_2D
:
324 conv
= &ctx
->Convolution2D
;
326 case GL_SEPARABLE_2D
:
328 conv
= &ctx
->Separable2D
;
331 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterfv(target)");
336 case GL_CONVOLUTION_BORDER_COLOR
:
337 COPY_4V(ctx
->Pixel
.ConvolutionBorderColor
[c
], params
);
339 case GL_CONVOLUTION_BORDER_MODE
:
340 if (params
[0] == (GLfloat
) GL_REDUCE
||
341 params
[0] == (GLfloat
) GL_CONSTANT_BORDER
||
342 params
[0] == (GLfloat
) GL_REPLICATE_BORDER
) {
343 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) params
[0];
346 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterfv(params)");
350 case GL_CONVOLUTION_FILTER_SCALE
:
351 COPY_4V(ctx
->Pixel
.ConvolutionFilterScale
[c
], params
);
353 case GL_CONVOLUTION_FILTER_BIAS
:
354 COPY_4V(ctx
->Pixel
.ConvolutionFilterBias
[c
], params
);
357 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterfv(pname)");
361 ctx
->NewState
|= _NEW_PIXEL
;
366 _mesa_ConvolutionParameteri(GLenum target
, GLenum pname
, GLint param
)
368 GET_CURRENT_CONTEXT(ctx
);
370 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
373 case GL_CONVOLUTION_1D
:
376 case GL_CONVOLUTION_2D
:
379 case GL_SEPARABLE_2D
:
383 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteri(target)");
388 case GL_CONVOLUTION_BORDER_MODE
:
389 if (param
== (GLint
) GL_REDUCE
||
390 param
== (GLint
) GL_CONSTANT_BORDER
||
391 param
== (GLint
) GL_REPLICATE_BORDER
) {
392 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) param
;
395 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteri(params)");
400 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteri(pname)");
404 ctx
->NewState
|= _NEW_PIXEL
;
409 _mesa_ConvolutionParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
411 GET_CURRENT_CONTEXT(ctx
);
412 struct gl_convolution_attrib
*conv
;
414 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
417 case GL_CONVOLUTION_1D
:
419 conv
= &ctx
->Convolution1D
;
421 case GL_CONVOLUTION_2D
:
423 conv
= &ctx
->Convolution2D
;
425 case GL_SEPARABLE_2D
:
427 conv
= &ctx
->Separable2D
;
430 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteriv(target)");
435 case GL_CONVOLUTION_BORDER_COLOR
:
436 ctx
->Pixel
.ConvolutionBorderColor
[c
][0] = INT_TO_FLOAT(params
[0]);
437 ctx
->Pixel
.ConvolutionBorderColor
[c
][1] = INT_TO_FLOAT(params
[1]);
438 ctx
->Pixel
.ConvolutionBorderColor
[c
][2] = INT_TO_FLOAT(params
[2]);
439 ctx
->Pixel
.ConvolutionBorderColor
[c
][3] = INT_TO_FLOAT(params
[3]);
441 case GL_CONVOLUTION_BORDER_MODE
:
442 if (params
[0] == (GLint
) GL_REDUCE
||
443 params
[0] == (GLint
) GL_CONSTANT_BORDER
||
444 params
[0] == (GLint
) GL_REPLICATE_BORDER
) {
445 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) params
[0];
448 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteriv(params)");
452 case GL_CONVOLUTION_FILTER_SCALE
:
453 COPY_4V(ctx
->Pixel
.ConvolutionFilterScale
[c
], params
);
455 case GL_CONVOLUTION_FILTER_BIAS
:
456 COPY_4V(ctx
->Pixel
.ConvolutionFilterBias
[c
], params
);
459 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteriv(pname)");
463 ctx
->NewState
|= _NEW_PIXEL
;
468 _mesa_CopyConvolutionFilter1D(GLenum target
, GLenum internalFormat
, GLint x
, GLint y
, GLsizei width
)
471 GET_CURRENT_CONTEXT(ctx
);
472 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
474 if (target
!= GL_CONVOLUTION_1D
) {
475 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter1D(target)");
479 baseFormat
= base_filter_format(internalFormat
);
480 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
481 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter1D(internalFormat)");
485 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
486 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyConvolutionFilter1D(width)");
490 ctx
->Driver
.CopyConvolutionFilter1D( ctx
, target
,
491 internalFormat
, x
, y
, width
);
496 _mesa_CopyConvolutionFilter2D(GLenum target
, GLenum internalFormat
, GLint x
, GLint y
, GLsizei width
, GLsizei height
)
499 GET_CURRENT_CONTEXT(ctx
);
500 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
502 if (target
!= GL_CONVOLUTION_2D
) {
503 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter2D(target)");
507 baseFormat
= base_filter_format(internalFormat
);
508 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
509 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter2D(internalFormat)");
513 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
514 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyConvolutionFilter2D(width)");
517 if (height
< 0 || height
> MAX_CONVOLUTION_HEIGHT
) {
518 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyConvolutionFilter2D(height)");
522 ctx
->Driver
.CopyConvolutionFilter2D( ctx
, target
, internalFormat
, x
, y
,
529 _mesa_GetConvolutionFilter(GLenum target
, GLenum format
, GLenum type
, GLvoid
*image
)
531 const struct gl_convolution_attrib
*filter
;
533 GET_CURRENT_CONTEXT(ctx
);
534 ASSERT_OUTSIDE_BEGIN_END(ctx
);
537 _mesa_update_state(ctx
);
540 if (!_mesa_is_legal_format_and_type(format
, type
)) {
541 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetConvolutionFilter(format or type)");
545 if (format
== GL_COLOR_INDEX
||
546 format
== GL_STENCIL_INDEX
||
547 format
== GL_DEPTH_COMPONENT
||
548 format
== GL_INTENSITY
||
550 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionFilter(format or type)");
555 case GL_CONVOLUTION_1D
:
556 filter
= &(ctx
->Convolution1D
);
558 case GL_CONVOLUTION_2D
:
559 filter
= &(ctx
->Convolution2D
);
562 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionFilter(target)");
566 for (row
= 0; row
< filter
->Height
; row
++) {
567 GLvoid
*dst
= _mesa_image_address( &ctx
->Pack
, image
, filter
->Width
,
568 filter
->Height
, format
, type
,
570 const GLfloat
*src
= filter
->Filter
+ row
* filter
->Width
* 4;
571 _mesa_pack_float_rgba_span(ctx
, filter
->Width
,
572 (const GLfloat (*)[4]) src
,
573 format
, type
, dst
, &ctx
->Pack
, 0);
579 _mesa_GetConvolutionParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
581 GET_CURRENT_CONTEXT(ctx
);
582 const struct gl_convolution_attrib
*conv
;
584 ASSERT_OUTSIDE_BEGIN_END(ctx
);
587 case GL_CONVOLUTION_1D
:
589 conv
= &ctx
->Convolution1D
;
591 case GL_CONVOLUTION_2D
:
593 conv
= &ctx
->Convolution2D
;
595 case GL_SEPARABLE_2D
:
597 conv
= &ctx
->Separable2D
;
600 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameterfv(target)");
605 case GL_CONVOLUTION_BORDER_COLOR
:
606 COPY_4V(params
, ctx
->Pixel
.ConvolutionBorderColor
[c
]);
608 case GL_CONVOLUTION_BORDER_MODE
:
609 *params
= (GLfloat
) ctx
->Pixel
.ConvolutionBorderMode
[c
];
611 case GL_CONVOLUTION_FILTER_SCALE
:
612 COPY_4V(params
, ctx
->Pixel
.ConvolutionFilterScale
[c
]);
614 case GL_CONVOLUTION_FILTER_BIAS
:
615 COPY_4V(params
, ctx
->Pixel
.ConvolutionFilterBias
[c
]);
617 case GL_CONVOLUTION_FORMAT
:
618 *params
= (GLfloat
) conv
->Format
;
620 case GL_CONVOLUTION_WIDTH
:
621 *params
= (GLfloat
) conv
->Width
;
623 case GL_CONVOLUTION_HEIGHT
:
624 *params
= (GLfloat
) conv
->Height
;
626 case GL_MAX_CONVOLUTION_WIDTH
:
627 *params
= (GLfloat
) ctx
->Const
.MaxConvolutionWidth
;
629 case GL_MAX_CONVOLUTION_HEIGHT
:
630 *params
= (GLfloat
) ctx
->Const
.MaxConvolutionHeight
;
633 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameterfv(pname)");
640 _mesa_GetConvolutionParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
642 GET_CURRENT_CONTEXT(ctx
);
643 const struct gl_convolution_attrib
*conv
;
645 ASSERT_OUTSIDE_BEGIN_END(ctx
);
648 case GL_CONVOLUTION_1D
:
650 conv
= &ctx
->Convolution1D
;
652 case GL_CONVOLUTION_2D
:
654 conv
= &ctx
->Convolution2D
;
656 case GL_SEPARABLE_2D
:
658 conv
= &ctx
->Separable2D
;
661 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameteriv(target)");
666 case GL_CONVOLUTION_BORDER_COLOR
:
667 params
[0] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][0]);
668 params
[1] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][1]);
669 params
[2] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][2]);
670 params
[3] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][3]);
672 case GL_CONVOLUTION_BORDER_MODE
:
673 *params
= (GLint
) ctx
->Pixel
.ConvolutionBorderMode
[c
];
675 case GL_CONVOLUTION_FILTER_SCALE
:
676 params
[0] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][0];
677 params
[1] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][1];
678 params
[2] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][2];
679 params
[3] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][3];
681 case GL_CONVOLUTION_FILTER_BIAS
:
682 params
[0] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][0];
683 params
[1] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][1];
684 params
[2] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][2];
685 params
[3] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][3];
687 case GL_CONVOLUTION_FORMAT
:
688 *params
= (GLint
) conv
->Format
;
690 case GL_CONVOLUTION_WIDTH
:
691 *params
= (GLint
) conv
->Width
;
693 case GL_CONVOLUTION_HEIGHT
:
694 *params
= (GLint
) conv
->Height
;
696 case GL_MAX_CONVOLUTION_WIDTH
:
697 *params
= (GLint
) ctx
->Const
.MaxConvolutionWidth
;
699 case GL_MAX_CONVOLUTION_HEIGHT
:
700 *params
= (GLint
) ctx
->Const
.MaxConvolutionHeight
;
703 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameteriv(pname)");
710 _mesa_GetSeparableFilter(GLenum target
, GLenum format
, GLenum type
, GLvoid
*row
, GLvoid
*column
, GLvoid
*span
)
712 const GLint colStart
= MAX_CONVOLUTION_WIDTH
* 4;
713 const struct gl_convolution_attrib
*filter
;
714 GET_CURRENT_CONTEXT(ctx
);
715 ASSERT_OUTSIDE_BEGIN_END(ctx
);
718 _mesa_update_state(ctx
);
721 if (target
!= GL_SEPARABLE_2D
) {
722 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSeparableFilter(target)");
726 if (!_mesa_is_legal_format_and_type(format
, type
)) {
727 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetConvolutionFilter(format or type)");
731 if (format
== GL_COLOR_INDEX
||
732 format
== GL_STENCIL_INDEX
||
733 format
== GL_DEPTH_COMPONENT
||
734 format
== GL_INTENSITY
||
736 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionFilter(format or type)");
740 filter
= &ctx
->Separable2D
;
744 GLvoid
*dst
= _mesa_image_address( &ctx
->Pack
, row
, filter
->Width
,
745 filter
->Height
, format
, type
,
747 _mesa_pack_float_rgba_span(ctx
, filter
->Width
,
748 (const GLfloat (*)[4]) filter
->Filter
,
749 format
, type
, dst
, &ctx
->Pack
, 0);
754 GLvoid
*dst
= _mesa_image_address( &ctx
->Pack
, column
, filter
->Width
,
757 const GLfloat
*src
= filter
->Filter
+ colStart
;
758 _mesa_pack_float_rgba_span(ctx
, filter
->Height
,
759 (const GLfloat (*)[4]) src
,
760 format
, type
, dst
, &ctx
->Pack
, 0);
763 (void) span
; /* unused at this time */
768 _mesa_SeparableFilter2D(GLenum target
, GLenum internalFormat
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, const GLvoid
*row
, const GLvoid
*column
)
770 const GLint colStart
= MAX_CONVOLUTION_WIDTH
* 4;
772 GET_CURRENT_CONTEXT(ctx
);
773 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
775 if (target
!= GL_SEPARABLE_2D
) {
776 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSeparableFilter2D(target)");
780 baseFormat
= base_filter_format(internalFormat
);
781 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
782 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSeparableFilter2D(internalFormat)");
786 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
787 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSeparableFilter2D(width)");
790 if (height
< 0 || height
> MAX_CONVOLUTION_HEIGHT
) {
791 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSeparableFilter2D(height)");
795 if (!_mesa_is_legal_format_and_type(format
, type
)) {
796 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glSeparableFilter2D(format or type)");
800 if (format
== GL_COLOR_INDEX
||
801 format
== GL_STENCIL_INDEX
||
802 format
== GL_DEPTH_COMPONENT
||
803 format
== GL_INTENSITY
||
805 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSeparableFilter2D(format or type)");
809 ctx
->Separable2D
.Format
= format
;
810 ctx
->Separable2D
.InternalFormat
= internalFormat
;
811 ctx
->Separable2D
.Width
= width
;
812 ctx
->Separable2D
.Height
= height
;
814 /* unpack row filter */
815 _mesa_unpack_float_color_span(ctx
, width
, GL_RGBA
,
816 ctx
->Separable2D
.Filter
,
817 format
, type
, row
, &ctx
->Unpack
,
820 /* apply scale and bias */
822 const GLfloat
*scale
= ctx
->Pixel
.ConvolutionFilterScale
[2];
823 const GLfloat
*bias
= ctx
->Pixel
.ConvolutionFilterBias
[2];
825 for (i
= 0; i
< width
; i
++) {
826 GLfloat r
= ctx
->Separable2D
.Filter
[i
* 4 + 0];
827 GLfloat g
= ctx
->Separable2D
.Filter
[i
* 4 + 1];
828 GLfloat b
= ctx
->Separable2D
.Filter
[i
* 4 + 2];
829 GLfloat a
= ctx
->Separable2D
.Filter
[i
* 4 + 3];
830 r
= r
* scale
[0] + bias
[0];
831 g
= g
* scale
[1] + bias
[1];
832 b
= b
* scale
[2] + bias
[2];
833 a
= a
* scale
[3] + bias
[3];
834 ctx
->Separable2D
.Filter
[i
* 4 + 0] = r
;
835 ctx
->Separable2D
.Filter
[i
* 4 + 1] = g
;
836 ctx
->Separable2D
.Filter
[i
* 4 + 2] = b
;
837 ctx
->Separable2D
.Filter
[i
* 4 + 3] = a
;
841 /* unpack column filter */
842 _mesa_unpack_float_color_span(ctx
, width
, GL_RGBA
,
843 &ctx
->Separable2D
.Filter
[colStart
],
844 format
, type
, column
, &ctx
->Unpack
,
847 /* apply scale and bias */
849 const GLfloat
*scale
= ctx
->Pixel
.ConvolutionFilterScale
[2];
850 const GLfloat
*bias
= ctx
->Pixel
.ConvolutionFilterBias
[2];
852 for (i
= 0; i
< width
; i
++) {
853 GLfloat r
= ctx
->Separable2D
.Filter
[i
* 4 + 0 + colStart
];
854 GLfloat g
= ctx
->Separable2D
.Filter
[i
* 4 + 1 + colStart
];
855 GLfloat b
= ctx
->Separable2D
.Filter
[i
* 4 + 2 + colStart
];
856 GLfloat a
= ctx
->Separable2D
.Filter
[i
* 4 + 3 + colStart
];
857 r
= r
* scale
[0] + bias
[0];
858 g
= g
* scale
[1] + bias
[1];
859 b
= b
* scale
[2] + bias
[2];
860 a
= a
* scale
[3] + bias
[3];
861 ctx
->Separable2D
.Filter
[i
* 4 + 0 + colStart
] = r
;
862 ctx
->Separable2D
.Filter
[i
* 4 + 1 + colStart
] = g
;
863 ctx
->Separable2D
.Filter
[i
* 4 + 2 + colStart
] = b
;
864 ctx
->Separable2D
.Filter
[i
* 4 + 3 + colStart
] = a
;
868 ctx
->NewState
|= _NEW_PIXEL
;
872 /**********************************************************************/
873 /*** image convolution functions ***/
874 /**********************************************************************/
877 convolve_1d_reduce(GLint srcWidth
, const GLfloat src
[][4],
878 GLint filterWidth
, const GLfloat filter
[][4],
884 if (filterWidth
>= 1)
885 dstWidth
= srcWidth
- (filterWidth
- 1);
890 return; /* null result */
892 for (i
= 0; i
< dstWidth
; i
++) {
897 for (n
= 0; n
< filterWidth
; n
++) {
898 sumR
+= src
[i
+ n
][RCOMP
] * filter
[n
][RCOMP
];
899 sumG
+= src
[i
+ n
][GCOMP
] * filter
[n
][GCOMP
];
900 sumB
+= src
[i
+ n
][BCOMP
] * filter
[n
][BCOMP
];
901 sumA
+= src
[i
+ n
][ACOMP
] * filter
[n
][ACOMP
];
903 dest
[i
][RCOMP
] = sumR
;
904 dest
[i
][GCOMP
] = sumG
;
905 dest
[i
][BCOMP
] = sumB
;
906 dest
[i
][ACOMP
] = sumA
;
912 convolve_1d_constant(GLint srcWidth
, const GLfloat src
[][4],
913 GLint filterWidth
, const GLfloat filter
[][4],
915 const GLfloat borderColor
[4])
917 const GLint halfFilterWidth
= filterWidth
/ 2;
920 for (i
= 0; i
< srcWidth
; i
++) {
925 for (n
= 0; n
< filterWidth
; n
++) {
926 if (i
+ n
< halfFilterWidth
|| i
+ n
- halfFilterWidth
>= srcWidth
) {
927 sumR
+= borderColor
[RCOMP
] * filter
[n
][RCOMP
];
928 sumG
+= borderColor
[GCOMP
] * filter
[n
][GCOMP
];
929 sumB
+= borderColor
[BCOMP
] * filter
[n
][BCOMP
];
930 sumA
+= borderColor
[ACOMP
] * filter
[n
][ACOMP
];
933 sumR
+= src
[i
+ n
- halfFilterWidth
][RCOMP
] * filter
[n
][RCOMP
];
934 sumG
+= src
[i
+ n
- halfFilterWidth
][GCOMP
] * filter
[n
][GCOMP
];
935 sumB
+= src
[i
+ n
- halfFilterWidth
][BCOMP
] * filter
[n
][BCOMP
];
936 sumA
+= src
[i
+ n
- halfFilterWidth
][ACOMP
] * filter
[n
][ACOMP
];
939 dest
[i
][RCOMP
] = sumR
;
940 dest
[i
][GCOMP
] = sumG
;
941 dest
[i
][BCOMP
] = sumB
;
942 dest
[i
][ACOMP
] = sumA
;
948 convolve_1d_replicate(GLint srcWidth
, const GLfloat src
[][4],
949 GLint filterWidth
, const GLfloat filter
[][4],
952 const GLint halfFilterWidth
= filterWidth
/ 2;
955 for (i
= 0; i
< srcWidth
; i
++) {
960 for (n
= 0; n
< filterWidth
; n
++) {
961 if (i
+ n
< halfFilterWidth
) {
962 sumR
+= src
[0][RCOMP
] * filter
[n
][RCOMP
];
963 sumG
+= src
[0][GCOMP
] * filter
[n
][GCOMP
];
964 sumB
+= src
[0][BCOMP
] * filter
[n
][BCOMP
];
965 sumA
+= src
[0][ACOMP
] * filter
[n
][ACOMP
];
967 else if (i
+ n
- halfFilterWidth
>= srcWidth
) {
968 sumR
+= src
[srcWidth
- 1][RCOMP
] * filter
[n
][RCOMP
];
969 sumG
+= src
[srcWidth
- 1][GCOMP
] * filter
[n
][GCOMP
];
970 sumB
+= src
[srcWidth
- 1][BCOMP
] * filter
[n
][BCOMP
];
971 sumA
+= src
[srcWidth
- 1][ACOMP
] * filter
[n
][ACOMP
];
974 sumR
+= src
[i
+ n
- halfFilterWidth
][RCOMP
] * filter
[n
][RCOMP
];
975 sumG
+= src
[i
+ n
- halfFilterWidth
][GCOMP
] * filter
[n
][GCOMP
];
976 sumB
+= src
[i
+ n
- halfFilterWidth
][BCOMP
] * filter
[n
][BCOMP
];
977 sumA
+= src
[i
+ n
- halfFilterWidth
][ACOMP
] * filter
[n
][ACOMP
];
980 dest
[i
][RCOMP
] = sumR
;
981 dest
[i
][GCOMP
] = sumG
;
982 dest
[i
][BCOMP
] = sumB
;
983 dest
[i
][ACOMP
] = sumA
;
989 convolve_2d_reduce(GLint srcWidth
, GLint srcHeight
,
990 const GLfloat src
[][4],
991 GLint filterWidth
, GLint filterHeight
,
992 const GLfloat filter
[][4],
995 GLint dstWidth
, dstHeight
;
998 if (filterWidth
>= 1)
999 dstWidth
= srcWidth
- (filterWidth
- 1);
1001 dstWidth
= srcWidth
;
1003 if (filterHeight
>= 1)
1004 dstHeight
= srcHeight
- (filterHeight
- 1);
1006 dstHeight
= srcHeight
;
1008 if (dstWidth
<= 0 || dstHeight
<= 0)
1011 for (j
= 0; j
< dstHeight
; j
++) {
1012 for (i
= 0; i
< dstWidth
; i
++) {
1017 for (m
= 0; m
< filterHeight
; m
++) {
1018 for (n
= 0; n
< filterWidth
; n
++) {
1019 const GLint k
= (j
+ m
) * srcWidth
+ i
+ n
;
1020 const GLint f
= m
* filterWidth
+ n
;
1021 sumR
+= src
[k
][RCOMP
] * filter
[f
][RCOMP
];
1022 sumG
+= src
[k
][GCOMP
] * filter
[f
][GCOMP
];
1023 sumB
+= src
[k
][BCOMP
] * filter
[f
][BCOMP
];
1024 sumA
+= src
[k
][ACOMP
] * filter
[f
][ACOMP
];
1027 dest
[j
* dstWidth
+ i
][RCOMP
] = sumR
;
1028 dest
[j
* dstWidth
+ i
][GCOMP
] = sumG
;
1029 dest
[j
* dstWidth
+ i
][BCOMP
] = sumB
;
1030 dest
[j
* dstWidth
+ i
][ACOMP
] = sumA
;
1037 convolve_2d_constant(GLint srcWidth
, GLint srcHeight
,
1038 const GLfloat src
[][4],
1039 GLint filterWidth
, GLint filterHeight
,
1040 const GLfloat filter
[][4],
1042 const GLfloat borderColor
[4])
1044 const GLint halfFilterWidth
= filterWidth
/ 2;
1045 const GLint halfFilterHeight
= filterHeight
/ 2;
1048 for (j
= 0; j
< srcHeight
; j
++) {
1049 for (i
= 0; i
< srcWidth
; i
++) {
1054 for (m
= 0; m
< filterHeight
; m
++) {
1055 for (n
= 0; n
< filterWidth
; n
++) {
1056 const GLint f
= m
* filterWidth
+ n
;
1057 const GLint is
= i
+ n
- halfFilterWidth
;
1058 const GLint js
= j
+ m
- halfFilterHeight
;
1059 if (is
< 0 || is
>= srcWidth
||
1060 js
< 0 || js
>= srcHeight
) {
1061 sumR
+= borderColor
[RCOMP
] * filter
[f
][RCOMP
];
1062 sumG
+= borderColor
[GCOMP
] * filter
[f
][GCOMP
];
1063 sumB
+= borderColor
[BCOMP
] * filter
[f
][BCOMP
];
1064 sumA
+= borderColor
[ACOMP
] * filter
[f
][ACOMP
];
1067 const GLint k
= js
* srcWidth
+ is
;
1068 sumR
+= src
[k
][RCOMP
] * filter
[f
][RCOMP
];
1069 sumG
+= src
[k
][GCOMP
] * filter
[f
][GCOMP
];
1070 sumB
+= src
[k
][BCOMP
] * filter
[f
][BCOMP
];
1071 sumA
+= src
[k
][ACOMP
] * filter
[f
][ACOMP
];
1075 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1076 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1077 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1078 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1085 convolve_2d_replicate(GLint srcWidth
, GLint srcHeight
,
1086 const GLfloat src
[][4],
1087 GLint filterWidth
, GLint filterHeight
,
1088 const GLfloat filter
[][4],
1091 const GLint halfFilterWidth
= filterWidth
/ 2;
1092 const GLint halfFilterHeight
= filterHeight
/ 2;
1095 for (j
= 0; j
< srcHeight
; j
++) {
1096 for (i
= 0; i
< srcWidth
; i
++) {
1101 for (m
= 0; m
< filterHeight
; m
++) {
1102 for (n
= 0; n
< filterWidth
; n
++) {
1103 const GLint f
= m
* filterWidth
+ n
;
1104 GLint is
= i
+ n
- halfFilterWidth
;
1105 GLint js
= j
+ m
- halfFilterHeight
;
1109 else if (is
>= srcWidth
)
1113 else if (js
>= srcHeight
)
1115 k
= js
* srcWidth
+ is
;
1116 sumR
+= src
[k
][RCOMP
] * filter
[f
][RCOMP
];
1117 sumG
+= src
[k
][GCOMP
] * filter
[f
][GCOMP
];
1118 sumB
+= src
[k
][BCOMP
] * filter
[f
][BCOMP
];
1119 sumA
+= src
[k
][ACOMP
] * filter
[f
][ACOMP
];
1122 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1123 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1124 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1125 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1132 convolve_sep_reduce(GLint srcWidth
, GLint srcHeight
,
1133 const GLfloat src
[][4],
1134 GLint filterWidth
, GLint filterHeight
,
1135 const GLfloat rowFilt
[][4],
1136 const GLfloat colFilt
[][4],
1139 GLint dstWidth
, dstHeight
;
1142 if (filterWidth
>= 1)
1143 dstWidth
= srcWidth
- (filterWidth
- 1);
1145 dstWidth
= srcWidth
;
1147 if (filterHeight
>= 1)
1148 dstHeight
= srcHeight
- (filterHeight
- 1);
1150 dstHeight
= srcHeight
;
1152 if (dstWidth
<= 0 || dstHeight
<= 0)
1155 for (j
= 0; j
< dstHeight
; j
++) {
1156 for (i
= 0; i
< dstWidth
; i
++) {
1161 for (m
= 0; m
< filterHeight
; m
++) {
1162 for (n
= 0; n
< filterWidth
; n
++) {
1163 GLint k
= (j
+ m
) * srcWidth
+ i
+ n
;
1164 sumR
+= src
[k
][RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1165 sumG
+= src
[k
][GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1166 sumB
+= src
[k
][BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1167 sumA
+= src
[k
][ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1170 dest
[j
* dstWidth
+ i
][RCOMP
] = sumR
;
1171 dest
[j
* dstWidth
+ i
][GCOMP
] = sumG
;
1172 dest
[j
* dstWidth
+ i
][BCOMP
] = sumB
;
1173 dest
[j
* dstWidth
+ i
][ACOMP
] = sumA
;
1180 convolve_sep_constant(GLint srcWidth
, GLint srcHeight
,
1181 const GLfloat src
[][4],
1182 GLint filterWidth
, GLint filterHeight
,
1183 const GLfloat rowFilt
[][4],
1184 const GLfloat colFilt
[][4],
1186 const GLfloat borderColor
[4])
1188 const GLint halfFilterWidth
= filterWidth
/ 2;
1189 const GLint halfFilterHeight
= filterHeight
/ 2;
1192 for (j
= 0; j
< srcHeight
; j
++) {
1193 for (i
= 0; i
< srcWidth
; i
++) {
1198 for (m
= 0; m
< filterHeight
; m
++) {
1199 for (n
= 0; n
< filterWidth
; n
++) {
1200 const GLint is
= i
+ n
- halfFilterWidth
;
1201 const GLint js
= j
+ m
- halfFilterHeight
;
1202 if (is
< 0 || is
>= srcWidth
||
1203 js
< 0 || js
>= srcHeight
) {
1204 sumR
+= borderColor
[RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1205 sumG
+= borderColor
[GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1206 sumB
+= borderColor
[BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1207 sumA
+= borderColor
[ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1210 GLint k
= js
* srcWidth
+ is
;
1211 sumR
+= src
[k
][RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1212 sumG
+= src
[k
][GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1213 sumB
+= src
[k
][BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1214 sumA
+= src
[k
][ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1219 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1220 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1221 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1222 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1229 convolve_sep_replicate(GLint srcWidth
, GLint srcHeight
,
1230 const GLfloat src
[][4],
1231 GLint filterWidth
, GLint filterHeight
,
1232 const GLfloat rowFilt
[][4],
1233 const GLfloat colFilt
[][4],
1236 const GLint halfFilterWidth
= filterWidth
/ 2;
1237 const GLint halfFilterHeight
= filterHeight
/ 2;
1240 for (j
= 0; j
< srcHeight
; j
++) {
1241 for (i
= 0; i
< srcWidth
; i
++) {
1246 for (m
= 0; m
< filterHeight
; m
++) {
1247 for (n
= 0; n
< filterWidth
; n
++) {
1248 GLint is
= i
+ n
- halfFilterWidth
;
1249 GLint js
= j
+ m
- halfFilterHeight
;
1253 else if (is
>= srcWidth
)
1257 else if (js
>= srcHeight
)
1259 k
= js
* srcWidth
+ is
;
1260 sumR
+= src
[k
][RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1261 sumG
+= src
[k
][GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1262 sumB
+= src
[k
][BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1263 sumA
+= src
[k
][ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1266 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1267 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1268 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1269 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1277 _mesa_convolve_1d_image(const GLcontext
*ctx
, GLsizei
*width
,
1278 const GLfloat
*srcImage
, GLfloat
*dstImage
)
1280 switch (ctx
->Pixel
.ConvolutionBorderMode
[0]) {
1282 convolve_1d_reduce(*width
, (const GLfloat (*)[4]) srcImage
,
1283 ctx
->Convolution1D
.Width
,
1284 (const GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
1285 (GLfloat (*)[4]) dstImage
);
1286 *width
= *width
- (MAX2(ctx
->Convolution1D
.Width
, 1) - 1);
1288 case GL_CONSTANT_BORDER
:
1289 convolve_1d_constant(*width
, (const GLfloat (*)[4]) srcImage
,
1290 ctx
->Convolution1D
.Width
,
1291 (const GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
1292 (GLfloat (*)[4]) dstImage
,
1293 ctx
->Pixel
.ConvolutionBorderColor
[0]);
1295 case GL_REPLICATE_BORDER
:
1296 convolve_1d_replicate(*width
, (const GLfloat (*)[4]) srcImage
,
1297 ctx
->Convolution1D
.Width
,
1298 (const GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
1299 (GLfloat (*)[4]) dstImage
);
1308 _mesa_convolve_2d_image(const GLcontext
*ctx
, GLsizei
*width
, GLsizei
*height
,
1309 const GLfloat
*srcImage
, GLfloat
*dstImage
)
1311 switch (ctx
->Pixel
.ConvolutionBorderMode
[1]) {
1313 convolve_2d_reduce(*width
, *height
,
1314 (const GLfloat (*)[4]) srcImage
,
1315 ctx
->Convolution2D
.Width
,
1316 ctx
->Convolution2D
.Height
,
1317 (const GLfloat (*)[4]) ctx
->Convolution2D
.Filter
,
1318 (GLfloat (*)[4]) dstImage
);
1319 *width
= *width
- (MAX2(ctx
->Convolution2D
.Width
, 1) - 1);
1320 *height
= *height
- (MAX2(ctx
->Convolution2D
.Height
, 1) - 1);
1322 case GL_CONSTANT_BORDER
:
1323 convolve_2d_constant(*width
, *height
,
1324 (const GLfloat (*)[4]) srcImage
,
1325 ctx
->Convolution2D
.Width
,
1326 ctx
->Convolution2D
.Height
,
1327 (const GLfloat (*)[4]) ctx
->Convolution2D
.Filter
,
1328 (GLfloat (*)[4]) dstImage
,
1329 ctx
->Pixel
.ConvolutionBorderColor
[1]);
1331 case GL_REPLICATE_BORDER
:
1332 convolve_2d_replicate(*width
, *height
,
1333 (const GLfloat (*)[4]) srcImage
,
1334 ctx
->Convolution2D
.Width
,
1335 ctx
->Convolution2D
.Height
,
1336 (const GLfloat (*)[4])ctx
->Convolution2D
.Filter
,
1337 (GLfloat (*)[4]) dstImage
);
1346 _mesa_convolve_sep_image(const GLcontext
*ctx
,
1347 GLsizei
*width
, GLsizei
*height
,
1348 const GLfloat
*srcImage
, GLfloat
*dstImage
)
1350 const GLfloat
*rowFilter
= ctx
->Separable2D
.Filter
;
1351 const GLfloat
*colFilter
= rowFilter
+ 4 * MAX_CONVOLUTION_WIDTH
;
1353 switch (ctx
->Pixel
.ConvolutionBorderMode
[2]) {
1355 convolve_sep_reduce(*width
, *height
,
1356 (const GLfloat (*)[4]) srcImage
,
1357 ctx
->Separable2D
.Width
,
1358 ctx
->Separable2D
.Height
,
1359 (const GLfloat (*)[4]) rowFilter
,
1360 (const GLfloat (*)[4]) colFilter
,
1361 (GLfloat (*)[4]) dstImage
);
1362 *width
= *width
- (MAX2(ctx
->Separable2D
.Width
, 1) - 1);
1363 *height
= *height
- (MAX2(ctx
->Separable2D
.Height
, 1) - 1);
1365 case GL_CONSTANT_BORDER
:
1366 convolve_sep_constant(*width
, *height
,
1367 (const GLfloat (*)[4]) srcImage
,
1368 ctx
->Separable2D
.Width
,
1369 ctx
->Separable2D
.Height
,
1370 (const GLfloat (*)[4]) rowFilter
,
1371 (const GLfloat (*)[4]) colFilter
,
1372 (GLfloat (*)[4]) dstImage
,
1373 ctx
->Pixel
.ConvolutionBorderColor
[2]);
1375 case GL_REPLICATE_BORDER
:
1376 convolve_sep_replicate(*width
, *height
,
1377 (const GLfloat (*)[4]) srcImage
,
1378 ctx
->Separable2D
.Width
,
1379 ctx
->Separable2D
.Height
,
1380 (const GLfloat (*)[4]) rowFilter
,
1381 (const GLfloat (*)[4]) colFilter
,
1382 (GLfloat (*)[4]) dstImage
);
1392 * This function computes an image's size after convolution.
1393 * If the convolution border mode is GL_REDUCE, the post-convolution
1394 * image will be smaller than the original.
1397 _mesa_adjust_image_for_convolution(const GLcontext
*ctx
, GLuint dimensions
,
1398 GLsizei
*width
, GLsizei
*height
)
1400 if (ctx
->Pixel
.Convolution1DEnabled
1402 && ctx
->Pixel
.ConvolutionBorderMode
[0] == GL_REDUCE
) {
1403 *width
= *width
- (MAX2(ctx
->Convolution1D
.Width
, 1) - 1);
1405 else if (ctx
->Pixel
.Convolution2DEnabled
1407 && ctx
->Pixel
.ConvolutionBorderMode
[1] == GL_REDUCE
) {
1408 *width
= *width
- (MAX2(ctx
->Convolution2D
.Width
, 1) - 1);
1409 *height
= *height
- (MAX2(ctx
->Convolution2D
.Height
, 1) - 1);
1411 else if (ctx
->Pixel
.Separable2DEnabled
1413 && ctx
->Pixel
.ConvolutionBorderMode
[2] == GL_REDUCE
) {
1414 *width
= *width
- (MAX2(ctx
->Separable2D
.Width
, 1) - 1);
1415 *height
= *height
- (MAX2(ctx
->Separable2D
.Height
, 1) - 1);