2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 * Image convolution functions.
29 * Notes: filter kernel elements are indexed by <n> and <m> as in
35 #include "bufferobj.h"
46 * Given an internalFormat token passed to glConvolutionFilter
47 * or glSeparableFilter, return the corresponding base format.
48 * Return -1 if invalid token.
51 base_filter_format( GLenum format
)
66 case GL_LUMINANCE_ALPHA
:
67 case GL_LUMINANCE4_ALPHA4
:
68 case GL_LUMINANCE6_ALPHA2
:
69 case GL_LUMINANCE8_ALPHA8
:
70 case GL_LUMINANCE12_ALPHA4
:
71 case GL_LUMINANCE12_ALPHA12
:
72 case GL_LUMINANCE16_ALPHA16
:
73 return GL_LUMINANCE_ALPHA
;
100 return -1; /* error */
106 _mesa_ConvolutionFilter1D(GLenum target
, GLenum internalFormat
, GLsizei width
, GLenum format
, GLenum type
, const GLvoid
*image
)
109 GET_CURRENT_CONTEXT(ctx
);
110 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
112 if (target
!= GL_CONVOLUTION_1D
) {
113 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter1D(target)");
117 baseFormat
= base_filter_format(internalFormat
);
118 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
119 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter1D(internalFormat)");
123 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
124 _mesa_error(ctx
, GL_INVALID_VALUE
, "glConvolutionFilter1D(width)");
128 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
129 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glConvolutionFilter1D(format or type)");
133 if (format
== GL_COLOR_INDEX
||
134 format
== GL_STENCIL_INDEX
||
135 format
== GL_DEPTH_COMPONENT
||
136 format
== GL_INTENSITY
||
138 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter1D(format or type)");
142 ctx
->Convolution1D
.Format
= format
;
143 ctx
->Convolution1D
.InternalFormat
= internalFormat
;
144 ctx
->Convolution1D
.Width
= width
;
145 ctx
->Convolution1D
.Height
= 1;
147 image
= _mesa_map_validate_pbo_source(ctx
,
148 1, &ctx
->Unpack
, width
, 1, 1,
150 "glConvolutionFilter1D");
154 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
,
155 ctx
->Convolution1D
.Filter
,
156 format
, type
, image
, &ctx
->Unpack
,
157 0); /* transferOps */
159 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
161 _mesa_scale_and_bias_rgba(width
,
162 (GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
163 ctx
->Pixel
.ConvolutionFilterScale
[0][0],
164 ctx
->Pixel
.ConvolutionFilterScale
[0][1],
165 ctx
->Pixel
.ConvolutionFilterScale
[0][2],
166 ctx
->Pixel
.ConvolutionFilterScale
[0][3],
167 ctx
->Pixel
.ConvolutionFilterBias
[0][0],
168 ctx
->Pixel
.ConvolutionFilterBias
[0][1],
169 ctx
->Pixel
.ConvolutionFilterBias
[0][2],
170 ctx
->Pixel
.ConvolutionFilterBias
[0][3]);
172 ctx
->NewState
|= _NEW_PIXEL
;
177 _mesa_ConvolutionFilter2D(GLenum target
, GLenum internalFormat
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, const GLvoid
*image
)
181 GET_CURRENT_CONTEXT(ctx
);
182 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
184 if (target
!= GL_CONVOLUTION_2D
) {
185 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter2D(target)");
189 baseFormat
= base_filter_format(internalFormat
);
190 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
191 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter2D(internalFormat)");
195 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
196 _mesa_error(ctx
, GL_INVALID_VALUE
, "glConvolutionFilter2D(width)");
199 if (height
< 0 || height
> MAX_CONVOLUTION_HEIGHT
) {
200 _mesa_error(ctx
, GL_INVALID_VALUE
, "glConvolutionFilter2D(height)");
204 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
205 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glConvolutionFilter2D(format or type)");
208 if (format
== GL_COLOR_INDEX
||
209 format
== GL_STENCIL_INDEX
||
210 format
== GL_DEPTH_COMPONENT
||
211 format
== GL_INTENSITY
||
213 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionFilter2D(format or type)");
217 /* this should have been caught earlier */
218 assert(_mesa_components_in_format(format
));
220 ctx
->Convolution2D
.Format
= format
;
221 ctx
->Convolution2D
.InternalFormat
= internalFormat
;
222 ctx
->Convolution2D
.Width
= width
;
223 ctx
->Convolution2D
.Height
= height
;
225 image
= _mesa_map_validate_pbo_source(ctx
,
226 2, &ctx
->Unpack
, width
, height
, 1,
228 "glConvolutionFilter2D");
232 /* Unpack filter image. We always store filters in RGBA format. */
233 for (i
= 0; i
< height
; i
++) {
234 const GLvoid
*src
= _mesa_image_address2d(&ctx
->Unpack
, image
, width
,
235 height
, format
, type
, i
, 0);
236 GLfloat
*dst
= ctx
->Convolution2D
.Filter
+ i
* width
* 4;
237 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, dst
,
238 format
, type
, src
, &ctx
->Unpack
,
239 0); /* transferOps */
242 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
244 _mesa_scale_and_bias_rgba(width
* height
,
245 (GLfloat (*)[4]) ctx
->Convolution2D
.Filter
,
246 ctx
->Pixel
.ConvolutionFilterScale
[1][0],
247 ctx
->Pixel
.ConvolutionFilterScale
[1][1],
248 ctx
->Pixel
.ConvolutionFilterScale
[1][2],
249 ctx
->Pixel
.ConvolutionFilterScale
[1][3],
250 ctx
->Pixel
.ConvolutionFilterBias
[1][0],
251 ctx
->Pixel
.ConvolutionFilterBias
[1][1],
252 ctx
->Pixel
.ConvolutionFilterBias
[1][2],
253 ctx
->Pixel
.ConvolutionFilterBias
[1][3]);
255 ctx
->NewState
|= _NEW_PIXEL
;
260 _mesa_ConvolutionParameterf(GLenum target
, GLenum pname
, GLfloat param
)
262 GET_CURRENT_CONTEXT(ctx
);
264 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
267 case GL_CONVOLUTION_1D
:
270 case GL_CONVOLUTION_2D
:
273 case GL_SEPARABLE_2D
:
277 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterf(target)");
282 case GL_CONVOLUTION_BORDER_MODE
:
283 if (param
== (GLfloat
) GL_REDUCE
||
284 param
== (GLfloat
) GL_CONSTANT_BORDER
||
285 param
== (GLfloat
) GL_REPLICATE_BORDER
) {
286 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) param
;
289 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterf(params)");
294 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterf(pname)");
298 ctx
->NewState
|= _NEW_PIXEL
;
303 _mesa_ConvolutionParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
305 GET_CURRENT_CONTEXT(ctx
);
307 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
310 case GL_CONVOLUTION_1D
:
313 case GL_CONVOLUTION_2D
:
316 case GL_SEPARABLE_2D
:
320 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterfv(target)");
325 case GL_CONVOLUTION_BORDER_COLOR
:
326 COPY_4V(ctx
->Pixel
.ConvolutionBorderColor
[c
], params
);
328 case GL_CONVOLUTION_BORDER_MODE
:
329 if (params
[0] == (GLfloat
) GL_REDUCE
||
330 params
[0] == (GLfloat
) GL_CONSTANT_BORDER
||
331 params
[0] == (GLfloat
) GL_REPLICATE_BORDER
) {
332 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) params
[0];
335 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterfv(params)");
339 case GL_CONVOLUTION_FILTER_SCALE
:
340 COPY_4V(ctx
->Pixel
.ConvolutionFilterScale
[c
], params
);
342 case GL_CONVOLUTION_FILTER_BIAS
:
343 COPY_4V(ctx
->Pixel
.ConvolutionFilterBias
[c
], params
);
346 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameterfv(pname)");
350 ctx
->NewState
|= _NEW_PIXEL
;
355 _mesa_ConvolutionParameteri(GLenum target
, GLenum pname
, GLint param
)
357 GET_CURRENT_CONTEXT(ctx
);
359 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
362 case GL_CONVOLUTION_1D
:
365 case GL_CONVOLUTION_2D
:
368 case GL_SEPARABLE_2D
:
372 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteri(target)");
377 case GL_CONVOLUTION_BORDER_MODE
:
378 if (param
== (GLint
) GL_REDUCE
||
379 param
== (GLint
) GL_CONSTANT_BORDER
||
380 param
== (GLint
) GL_REPLICATE_BORDER
) {
381 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) param
;
384 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteri(params)");
389 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteri(pname)");
393 ctx
->NewState
|= _NEW_PIXEL
;
398 _mesa_ConvolutionParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
400 GET_CURRENT_CONTEXT(ctx
);
402 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
405 case GL_CONVOLUTION_1D
:
408 case GL_CONVOLUTION_2D
:
411 case GL_SEPARABLE_2D
:
415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteriv(target)");
420 case GL_CONVOLUTION_BORDER_COLOR
:
421 ctx
->Pixel
.ConvolutionBorderColor
[c
][0] = INT_TO_FLOAT(params
[0]);
422 ctx
->Pixel
.ConvolutionBorderColor
[c
][1] = INT_TO_FLOAT(params
[1]);
423 ctx
->Pixel
.ConvolutionBorderColor
[c
][2] = INT_TO_FLOAT(params
[2]);
424 ctx
->Pixel
.ConvolutionBorderColor
[c
][3] = INT_TO_FLOAT(params
[3]);
426 case GL_CONVOLUTION_BORDER_MODE
:
427 if (params
[0] == (GLint
) GL_REDUCE
||
428 params
[0] == (GLint
) GL_CONSTANT_BORDER
||
429 params
[0] == (GLint
) GL_REPLICATE_BORDER
) {
430 ctx
->Pixel
.ConvolutionBorderMode
[c
] = (GLenum
) params
[0];
433 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteriv(params)");
437 case GL_CONVOLUTION_FILTER_SCALE
:
438 /* COPY_4V(ctx->Pixel.ConvolutionFilterScale[c], params); */
439 /* need cast to prevent compiler warnings */
440 ctx
->Pixel
.ConvolutionFilterScale
[c
][0] = (GLfloat
) params
[0];
441 ctx
->Pixel
.ConvolutionFilterScale
[c
][1] = (GLfloat
) params
[1];
442 ctx
->Pixel
.ConvolutionFilterScale
[c
][2] = (GLfloat
) params
[2];
443 ctx
->Pixel
.ConvolutionFilterScale
[c
][3] = (GLfloat
) params
[3];
445 case GL_CONVOLUTION_FILTER_BIAS
:
446 /* COPY_4V(ctx->Pixel.ConvolutionFilterBias[c], params); */
447 /* need cast to prevent compiler warnings */
448 ctx
->Pixel
.ConvolutionFilterBias
[c
][0] = (GLfloat
) params
[0];
449 ctx
->Pixel
.ConvolutionFilterBias
[c
][1] = (GLfloat
) params
[1];
450 ctx
->Pixel
.ConvolutionFilterBias
[c
][2] = (GLfloat
) params
[2];
451 ctx
->Pixel
.ConvolutionFilterBias
[c
][3] = (GLfloat
) params
[3];
454 _mesa_error(ctx
, GL_INVALID_ENUM
, "glConvolutionParameteriv(pname)");
458 ctx
->NewState
|= _NEW_PIXEL
;
463 _mesa_CopyConvolutionFilter1D(GLenum target
, GLenum internalFormat
, GLint x
, GLint y
, GLsizei width
)
466 GET_CURRENT_CONTEXT(ctx
);
467 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
469 if (target
!= GL_CONVOLUTION_1D
) {
470 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter1D(target)");
474 baseFormat
= base_filter_format(internalFormat
);
475 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
476 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter1D(internalFormat)");
480 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
481 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyConvolutionFilter1D(width)");
485 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
486 return; /* no readbuffer - OK */
489 ctx
->Driver
.CopyConvolutionFilter1D( ctx
, target
,
490 internalFormat
, x
, y
, width
);
495 _mesa_CopyConvolutionFilter2D(GLenum target
, GLenum internalFormat
, GLint x
, GLint y
, GLsizei width
, GLsizei height
)
498 GET_CURRENT_CONTEXT(ctx
);
499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
501 if (target
!= GL_CONVOLUTION_2D
) {
502 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter2D(target)");
506 baseFormat
= base_filter_format(internalFormat
);
507 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyConvolutionFilter2D(internalFormat)");
512 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
513 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyConvolutionFilter2D(width)");
516 if (height
< 0 || height
> MAX_CONVOLUTION_HEIGHT
) {
517 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyConvolutionFilter2D(height)");
521 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
522 return; /* no readbuffer - OK */
525 ctx
->Driver
.CopyConvolutionFilter2D( ctx
, target
, internalFormat
, x
, y
,
531 _mesa_GetConvolutionFilter(GLenum target
, GLenum format
, GLenum type
,
534 struct gl_convolution_attrib
*filter
;
536 GET_CURRENT_CONTEXT(ctx
);
537 ASSERT_OUTSIDE_BEGIN_END(ctx
);
540 _mesa_update_state(ctx
);
543 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
544 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetConvolutionFilter(format or type)");
548 if (format
== GL_COLOR_INDEX
||
549 format
== GL_STENCIL_INDEX
||
550 format
== GL_DEPTH_COMPONENT
||
551 format
== GL_INTENSITY
||
553 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionFilter(format or type)");
558 case GL_CONVOLUTION_1D
:
559 filter
= &(ctx
->Convolution1D
);
561 case GL_CONVOLUTION_2D
:
562 filter
= &(ctx
->Convolution2D
);
565 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionFilter(target)");
569 image
= _mesa_map_validate_pbo_dest(ctx
, 2, &ctx
->Pack
,
570 filter
->Width
, filter
->Height
, 1,
572 "glGetConvolutionFilter");
576 for (row
= 0; row
< filter
->Height
; row
++) {
577 GLvoid
*dst
= _mesa_image_address2d(&ctx
->Pack
, image
, filter
->Width
,
578 filter
->Height
, format
, type
,
580 GLfloat (*src
)[4] = (GLfloat (*)[4]) (filter
->Filter
+ row
* filter
->Width
* 4);
581 _mesa_pack_rgba_span_float(ctx
, filter
->Width
, src
,
582 format
, type
, dst
, &ctx
->Pack
, 0x0);
585 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
590 _mesa_GetConvolutionParameterfv(GLenum target
, GLenum pname
, GLfloat
*params
)
592 GET_CURRENT_CONTEXT(ctx
);
593 const struct gl_convolution_attrib
*conv
;
595 ASSERT_OUTSIDE_BEGIN_END(ctx
);
598 case GL_CONVOLUTION_1D
:
600 conv
= &ctx
->Convolution1D
;
602 case GL_CONVOLUTION_2D
:
604 conv
= &ctx
->Convolution2D
;
606 case GL_SEPARABLE_2D
:
608 conv
= &ctx
->Separable2D
;
611 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameterfv(target)");
616 case GL_CONVOLUTION_BORDER_COLOR
:
617 COPY_4V(params
, ctx
->Pixel
.ConvolutionBorderColor
[c
]);
619 case GL_CONVOLUTION_BORDER_MODE
:
620 *params
= (GLfloat
) ctx
->Pixel
.ConvolutionBorderMode
[c
];
622 case GL_CONVOLUTION_FILTER_SCALE
:
623 COPY_4V(params
, ctx
->Pixel
.ConvolutionFilterScale
[c
]);
625 case GL_CONVOLUTION_FILTER_BIAS
:
626 COPY_4V(params
, ctx
->Pixel
.ConvolutionFilterBias
[c
]);
628 case GL_CONVOLUTION_FORMAT
:
629 *params
= (GLfloat
) conv
->Format
;
631 case GL_CONVOLUTION_WIDTH
:
632 *params
= (GLfloat
) conv
->Width
;
634 case GL_CONVOLUTION_HEIGHT
:
635 *params
= (GLfloat
) conv
->Height
;
637 case GL_MAX_CONVOLUTION_WIDTH
:
638 *params
= (GLfloat
) ctx
->Const
.MaxConvolutionWidth
;
640 case GL_MAX_CONVOLUTION_HEIGHT
:
641 *params
= (GLfloat
) ctx
->Const
.MaxConvolutionHeight
;
644 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameterfv(pname)");
651 _mesa_GetConvolutionParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
653 GET_CURRENT_CONTEXT(ctx
);
654 const struct gl_convolution_attrib
*conv
;
656 ASSERT_OUTSIDE_BEGIN_END(ctx
);
659 case GL_CONVOLUTION_1D
:
661 conv
= &ctx
->Convolution1D
;
663 case GL_CONVOLUTION_2D
:
665 conv
= &ctx
->Convolution2D
;
667 case GL_SEPARABLE_2D
:
669 conv
= &ctx
->Separable2D
;
672 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameteriv(target)");
677 case GL_CONVOLUTION_BORDER_COLOR
:
678 params
[0] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][0]);
679 params
[1] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][1]);
680 params
[2] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][2]);
681 params
[3] = FLOAT_TO_INT(ctx
->Pixel
.ConvolutionBorderColor
[c
][3]);
683 case GL_CONVOLUTION_BORDER_MODE
:
684 *params
= (GLint
) ctx
->Pixel
.ConvolutionBorderMode
[c
];
686 case GL_CONVOLUTION_FILTER_SCALE
:
687 params
[0] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][0];
688 params
[1] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][1];
689 params
[2] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][2];
690 params
[3] = (GLint
) ctx
->Pixel
.ConvolutionFilterScale
[c
][3];
692 case GL_CONVOLUTION_FILTER_BIAS
:
693 params
[0] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][0];
694 params
[1] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][1];
695 params
[2] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][2];
696 params
[3] = (GLint
) ctx
->Pixel
.ConvolutionFilterBias
[c
][3];
698 case GL_CONVOLUTION_FORMAT
:
699 *params
= (GLint
) conv
->Format
;
701 case GL_CONVOLUTION_WIDTH
:
702 *params
= (GLint
) conv
->Width
;
704 case GL_CONVOLUTION_HEIGHT
:
705 *params
= (GLint
) conv
->Height
;
707 case GL_MAX_CONVOLUTION_WIDTH
:
708 *params
= (GLint
) ctx
->Const
.MaxConvolutionWidth
;
710 case GL_MAX_CONVOLUTION_HEIGHT
:
711 *params
= (GLint
) ctx
->Const
.MaxConvolutionHeight
;
714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionParameteriv(pname)");
721 _mesa_GetSeparableFilter(GLenum target
, GLenum format
, GLenum type
,
722 GLvoid
*row
, GLvoid
*column
, GLvoid
*span
)
724 const GLint colStart
= MAX_CONVOLUTION_WIDTH
* 4;
725 struct gl_convolution_attrib
*filter
;
726 GET_CURRENT_CONTEXT(ctx
);
727 ASSERT_OUTSIDE_BEGIN_END(ctx
);
730 _mesa_update_state(ctx
);
733 if (target
!= GL_SEPARABLE_2D
) {
734 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetSeparableFilter(target)");
738 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
739 _mesa_error(ctx
, GL_INVALID_OPERATION
,
740 "glGetConvolutionFilter(format or type)");
744 if (format
== GL_COLOR_INDEX
||
745 format
== GL_STENCIL_INDEX
||
746 format
== GL_DEPTH_COMPONENT
||
747 format
== GL_INTENSITY
||
749 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetConvolutionFilter(format or type)");
753 filter
= &ctx
->Separable2D
;
756 row
= _mesa_map_validate_pbo_dest(ctx
, 1, &ctx
->Pack
,
759 "glGetConvolutionFilter");
761 GLvoid
*dst
= _mesa_image_address1d(&ctx
->Pack
, row
, filter
->Width
,
763 _mesa_pack_rgba_span_float(ctx
, filter
->Width
,
764 (GLfloat (*)[4]) filter
->Filter
,
765 format
, type
, dst
, &ctx
->Pack
, 0x0);
766 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
769 /* get column filter */
770 column
= _mesa_map_validate_pbo_dest(ctx
, 1, &ctx
->Pack
,
771 filter
->Height
, 1, 1,
772 format
, type
, column
,
773 "glGetConvolutionFilter");
775 GLvoid
*dst
= _mesa_image_address1d(&ctx
->Pack
, column
, filter
->Height
,
777 GLfloat (*src
)[4] = (GLfloat (*)[4]) (filter
->Filter
+ colStart
);
778 _mesa_pack_rgba_span_float(ctx
, filter
->Height
, src
,
779 format
, type
, dst
, &ctx
->Pack
, 0x0);
780 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
783 (void) span
; /* unused at this time */
788 _mesa_SeparableFilter2D(GLenum target
, GLenum internalFormat
, GLsizei width
, GLsizei height
, GLenum format
, GLenum type
, const GLvoid
*row
, const GLvoid
*column
)
790 const GLint colStart
= MAX_CONVOLUTION_WIDTH
* 4;
792 GET_CURRENT_CONTEXT(ctx
);
793 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
795 if (target
!= GL_SEPARABLE_2D
) {
796 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSeparableFilter2D(target)");
800 baseFormat
= base_filter_format(internalFormat
);
801 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSeparableFilter2D(internalFormat)");
806 if (width
< 0 || width
> MAX_CONVOLUTION_WIDTH
) {
807 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSeparableFilter2D(width)");
810 if (height
< 0 || height
> MAX_CONVOLUTION_HEIGHT
) {
811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSeparableFilter2D(height)");
815 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
816 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glSeparableFilter2D(format or type)");
820 if (format
== GL_COLOR_INDEX
||
821 format
== GL_STENCIL_INDEX
||
822 format
== GL_DEPTH_COMPONENT
||
823 format
== GL_INTENSITY
||
825 _mesa_error(ctx
, GL_INVALID_ENUM
, "glSeparableFilter2D(format or type)");
829 ctx
->Separable2D
.Format
= format
;
830 ctx
->Separable2D
.InternalFormat
= internalFormat
;
831 ctx
->Separable2D
.Width
= width
;
832 ctx
->Separable2D
.Height
= height
;
834 /* unpack row filter */
835 row
= _mesa_map_validate_pbo_source(ctx
, 1, &ctx
->Unpack
,
838 "glSeparableFilter2D");
840 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
,
841 ctx
->Separable2D
.Filter
,
842 format
, type
, row
, &ctx
->Unpack
,
843 0x0); /* transferOps */
844 _mesa_scale_and_bias_rgba(width
,
845 (GLfloat (*)[4]) ctx
->Separable2D
.Filter
,
846 ctx
->Pixel
.ConvolutionFilterScale
[2][0],
847 ctx
->Pixel
.ConvolutionFilterScale
[2][1],
848 ctx
->Pixel
.ConvolutionFilterScale
[2][2],
849 ctx
->Pixel
.ConvolutionFilterScale
[2][3],
850 ctx
->Pixel
.ConvolutionFilterBias
[2][0],
851 ctx
->Pixel
.ConvolutionFilterBias
[2][1],
852 ctx
->Pixel
.ConvolutionFilterBias
[2][2],
853 ctx
->Pixel
.ConvolutionFilterBias
[2][3]);
854 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
857 /* unpack column filter */
858 column
= _mesa_map_validate_pbo_source(ctx
, 1, &ctx
->Unpack
,
860 format
, type
, column
,
861 "glSeparableFilter2D");
863 _mesa_unpack_color_span_float(ctx
, height
, GL_RGBA
,
864 &ctx
->Separable2D
.Filter
[colStart
],
865 format
, type
, column
, &ctx
->Unpack
,
866 0); /* transferOps */
868 _mesa_scale_and_bias_rgba(height
,
869 (GLfloat (*)[4]) (ctx
->Separable2D
.Filter
+ colStart
),
870 ctx
->Pixel
.ConvolutionFilterScale
[2][0],
871 ctx
->Pixel
.ConvolutionFilterScale
[2][1],
872 ctx
->Pixel
.ConvolutionFilterScale
[2][2],
873 ctx
->Pixel
.ConvolutionFilterScale
[2][3],
874 ctx
->Pixel
.ConvolutionFilterBias
[2][0],
875 ctx
->Pixel
.ConvolutionFilterBias
[2][1],
876 ctx
->Pixel
.ConvolutionFilterBias
[2][2],
877 ctx
->Pixel
.ConvolutionFilterBias
[2][3]);
878 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
881 if (_mesa_is_bufferobj(ctx
->Unpack
.BufferObj
)) {
882 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
883 ctx
->Unpack
.BufferObj
);
886 ctx
->NewState
|= _NEW_PIXEL
;
890 /**********************************************************************/
891 /*** image convolution functions ***/
892 /**********************************************************************/
895 convolve_1d_reduce(GLint srcWidth
, const GLfloat src
[][4],
896 GLint filterWidth
, const GLfloat filter
[][4],
902 if (filterWidth
>= 1)
903 dstWidth
= srcWidth
- (filterWidth
- 1);
908 return; /* null result */
910 for (i
= 0; i
< dstWidth
; i
++) {
915 for (n
= 0; n
< filterWidth
; n
++) {
916 sumR
+= src
[i
+ n
][RCOMP
] * filter
[n
][RCOMP
];
917 sumG
+= src
[i
+ n
][GCOMP
] * filter
[n
][GCOMP
];
918 sumB
+= src
[i
+ n
][BCOMP
] * filter
[n
][BCOMP
];
919 sumA
+= src
[i
+ n
][ACOMP
] * filter
[n
][ACOMP
];
921 dest
[i
][RCOMP
] = sumR
;
922 dest
[i
][GCOMP
] = sumG
;
923 dest
[i
][BCOMP
] = sumB
;
924 dest
[i
][ACOMP
] = sumA
;
930 convolve_1d_constant(GLint srcWidth
, const GLfloat src
[][4],
931 GLint filterWidth
, const GLfloat filter
[][4],
933 const GLfloat borderColor
[4])
935 const GLint halfFilterWidth
= filterWidth
/ 2;
938 for (i
= 0; i
< srcWidth
; i
++) {
943 for (n
= 0; n
< filterWidth
; n
++) {
944 if (i
+ n
< halfFilterWidth
|| i
+ n
- halfFilterWidth
>= srcWidth
) {
945 sumR
+= borderColor
[RCOMP
] * filter
[n
][RCOMP
];
946 sumG
+= borderColor
[GCOMP
] * filter
[n
][GCOMP
];
947 sumB
+= borderColor
[BCOMP
] * filter
[n
][BCOMP
];
948 sumA
+= borderColor
[ACOMP
] * filter
[n
][ACOMP
];
951 sumR
+= src
[i
+ n
- halfFilterWidth
][RCOMP
] * filter
[n
][RCOMP
];
952 sumG
+= src
[i
+ n
- halfFilterWidth
][GCOMP
] * filter
[n
][GCOMP
];
953 sumB
+= src
[i
+ n
- halfFilterWidth
][BCOMP
] * filter
[n
][BCOMP
];
954 sumA
+= src
[i
+ n
- halfFilterWidth
][ACOMP
] * filter
[n
][ACOMP
];
957 dest
[i
][RCOMP
] = sumR
;
958 dest
[i
][GCOMP
] = sumG
;
959 dest
[i
][BCOMP
] = sumB
;
960 dest
[i
][ACOMP
] = sumA
;
966 convolve_1d_replicate(GLint srcWidth
, const GLfloat src
[][4],
967 GLint filterWidth
, const GLfloat filter
[][4],
970 const GLint halfFilterWidth
= filterWidth
/ 2;
973 for (i
= 0; i
< srcWidth
; i
++) {
978 for (n
= 0; n
< filterWidth
; n
++) {
979 if (i
+ n
< halfFilterWidth
) {
980 sumR
+= src
[0][RCOMP
] * filter
[n
][RCOMP
];
981 sumG
+= src
[0][GCOMP
] * filter
[n
][GCOMP
];
982 sumB
+= src
[0][BCOMP
] * filter
[n
][BCOMP
];
983 sumA
+= src
[0][ACOMP
] * filter
[n
][ACOMP
];
985 else if (i
+ n
- halfFilterWidth
>= srcWidth
) {
986 sumR
+= src
[srcWidth
- 1][RCOMP
] * filter
[n
][RCOMP
];
987 sumG
+= src
[srcWidth
- 1][GCOMP
] * filter
[n
][GCOMP
];
988 sumB
+= src
[srcWidth
- 1][BCOMP
] * filter
[n
][BCOMP
];
989 sumA
+= src
[srcWidth
- 1][ACOMP
] * filter
[n
][ACOMP
];
992 sumR
+= src
[i
+ n
- halfFilterWidth
][RCOMP
] * filter
[n
][RCOMP
];
993 sumG
+= src
[i
+ n
- halfFilterWidth
][GCOMP
] * filter
[n
][GCOMP
];
994 sumB
+= src
[i
+ n
- halfFilterWidth
][BCOMP
] * filter
[n
][BCOMP
];
995 sumA
+= src
[i
+ n
- halfFilterWidth
][ACOMP
] * filter
[n
][ACOMP
];
998 dest
[i
][RCOMP
] = sumR
;
999 dest
[i
][GCOMP
] = sumG
;
1000 dest
[i
][BCOMP
] = sumB
;
1001 dest
[i
][ACOMP
] = sumA
;
1007 convolve_2d_reduce(GLint srcWidth
, GLint srcHeight
,
1008 const GLfloat src
[][4],
1009 GLint filterWidth
, GLint filterHeight
,
1010 const GLfloat filter
[][4],
1013 GLint dstWidth
, dstHeight
;
1016 if (filterWidth
>= 1)
1017 dstWidth
= srcWidth
- (filterWidth
- 1);
1019 dstWidth
= srcWidth
;
1021 if (filterHeight
>= 1)
1022 dstHeight
= srcHeight
- (filterHeight
- 1);
1024 dstHeight
= srcHeight
;
1026 if (dstWidth
<= 0 || dstHeight
<= 0)
1029 for (j
= 0; j
< dstHeight
; j
++) {
1030 for (i
= 0; i
< dstWidth
; i
++) {
1035 for (m
= 0; m
< filterHeight
; m
++) {
1036 for (n
= 0; n
< filterWidth
; n
++) {
1037 const GLint k
= (j
+ m
) * srcWidth
+ i
+ n
;
1038 const GLint f
= m
* filterWidth
+ n
;
1039 sumR
+= src
[k
][RCOMP
] * filter
[f
][RCOMP
];
1040 sumG
+= src
[k
][GCOMP
] * filter
[f
][GCOMP
];
1041 sumB
+= src
[k
][BCOMP
] * filter
[f
][BCOMP
];
1042 sumA
+= src
[k
][ACOMP
] * filter
[f
][ACOMP
];
1045 dest
[j
* dstWidth
+ i
][RCOMP
] = sumR
;
1046 dest
[j
* dstWidth
+ i
][GCOMP
] = sumG
;
1047 dest
[j
* dstWidth
+ i
][BCOMP
] = sumB
;
1048 dest
[j
* dstWidth
+ i
][ACOMP
] = sumA
;
1055 convolve_2d_constant(GLint srcWidth
, GLint srcHeight
,
1056 const GLfloat src
[][4],
1057 GLint filterWidth
, GLint filterHeight
,
1058 const GLfloat filter
[][4],
1060 const GLfloat borderColor
[4])
1062 const GLint halfFilterWidth
= filterWidth
/ 2;
1063 const GLint halfFilterHeight
= filterHeight
/ 2;
1066 for (j
= 0; j
< srcHeight
; j
++) {
1067 for (i
= 0; i
< srcWidth
; i
++) {
1072 for (m
= 0; m
< filterHeight
; m
++) {
1073 for (n
= 0; n
< filterWidth
; n
++) {
1074 const GLint f
= m
* filterWidth
+ n
;
1075 const GLint is
= i
+ n
- halfFilterWidth
;
1076 const GLint js
= j
+ m
- halfFilterHeight
;
1077 if (is
< 0 || is
>= srcWidth
||
1078 js
< 0 || js
>= srcHeight
) {
1079 sumR
+= borderColor
[RCOMP
] * filter
[f
][RCOMP
];
1080 sumG
+= borderColor
[GCOMP
] * filter
[f
][GCOMP
];
1081 sumB
+= borderColor
[BCOMP
] * filter
[f
][BCOMP
];
1082 sumA
+= borderColor
[ACOMP
] * filter
[f
][ACOMP
];
1085 const GLint k
= js
* srcWidth
+ is
;
1086 sumR
+= src
[k
][RCOMP
] * filter
[f
][RCOMP
];
1087 sumG
+= src
[k
][GCOMP
] * filter
[f
][GCOMP
];
1088 sumB
+= src
[k
][BCOMP
] * filter
[f
][BCOMP
];
1089 sumA
+= src
[k
][ACOMP
] * filter
[f
][ACOMP
];
1093 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1094 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1095 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1096 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1103 convolve_2d_replicate(GLint srcWidth
, GLint srcHeight
,
1104 const GLfloat src
[][4],
1105 GLint filterWidth
, GLint filterHeight
,
1106 const GLfloat filter
[][4],
1109 const GLint halfFilterWidth
= filterWidth
/ 2;
1110 const GLint halfFilterHeight
= filterHeight
/ 2;
1113 for (j
= 0; j
< srcHeight
; j
++) {
1114 for (i
= 0; i
< srcWidth
; i
++) {
1119 for (m
= 0; m
< filterHeight
; m
++) {
1120 for (n
= 0; n
< filterWidth
; n
++) {
1121 const GLint f
= m
* filterWidth
+ n
;
1122 GLint is
= i
+ n
- halfFilterWidth
;
1123 GLint js
= j
+ m
- halfFilterHeight
;
1127 else if (is
>= srcWidth
)
1131 else if (js
>= srcHeight
)
1133 k
= js
* srcWidth
+ is
;
1134 sumR
+= src
[k
][RCOMP
] * filter
[f
][RCOMP
];
1135 sumG
+= src
[k
][GCOMP
] * filter
[f
][GCOMP
];
1136 sumB
+= src
[k
][BCOMP
] * filter
[f
][BCOMP
];
1137 sumA
+= src
[k
][ACOMP
] * filter
[f
][ACOMP
];
1140 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1141 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1142 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1143 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1150 convolve_sep_reduce(GLint srcWidth
, GLint srcHeight
,
1151 const GLfloat src
[][4],
1152 GLint filterWidth
, GLint filterHeight
,
1153 const GLfloat rowFilt
[][4],
1154 const GLfloat colFilt
[][4],
1157 GLint dstWidth
, dstHeight
;
1160 if (filterWidth
>= 1)
1161 dstWidth
= srcWidth
- (filterWidth
- 1);
1163 dstWidth
= srcWidth
;
1165 if (filterHeight
>= 1)
1166 dstHeight
= srcHeight
- (filterHeight
- 1);
1168 dstHeight
= srcHeight
;
1170 if (dstWidth
<= 0 || dstHeight
<= 0)
1173 for (j
= 0; j
< dstHeight
; j
++) {
1174 for (i
= 0; i
< dstWidth
; i
++) {
1179 for (m
= 0; m
< filterHeight
; m
++) {
1180 for (n
= 0; n
< filterWidth
; n
++) {
1181 GLint k
= (j
+ m
) * srcWidth
+ i
+ n
;
1182 sumR
+= src
[k
][RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1183 sumG
+= src
[k
][GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1184 sumB
+= src
[k
][BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1185 sumA
+= src
[k
][ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1188 dest
[j
* dstWidth
+ i
][RCOMP
] = sumR
;
1189 dest
[j
* dstWidth
+ i
][GCOMP
] = sumG
;
1190 dest
[j
* dstWidth
+ i
][BCOMP
] = sumB
;
1191 dest
[j
* dstWidth
+ i
][ACOMP
] = sumA
;
1198 convolve_sep_constant(GLint srcWidth
, GLint srcHeight
,
1199 const GLfloat src
[][4],
1200 GLint filterWidth
, GLint filterHeight
,
1201 const GLfloat rowFilt
[][4],
1202 const GLfloat colFilt
[][4],
1204 const GLfloat borderColor
[4])
1206 const GLint halfFilterWidth
= filterWidth
/ 2;
1207 const GLint halfFilterHeight
= filterHeight
/ 2;
1210 for (j
= 0; j
< srcHeight
; j
++) {
1211 for (i
= 0; i
< srcWidth
; i
++) {
1216 for (m
= 0; m
< filterHeight
; m
++) {
1217 for (n
= 0; n
< filterWidth
; n
++) {
1218 const GLint is
= i
+ n
- halfFilterWidth
;
1219 const GLint js
= j
+ m
- halfFilterHeight
;
1220 if (is
< 0 || is
>= srcWidth
||
1221 js
< 0 || js
>= srcHeight
) {
1222 sumR
+= borderColor
[RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1223 sumG
+= borderColor
[GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1224 sumB
+= borderColor
[BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1225 sumA
+= borderColor
[ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1228 GLint k
= js
* srcWidth
+ is
;
1229 sumR
+= src
[k
][RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1230 sumG
+= src
[k
][GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1231 sumB
+= src
[k
][BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1232 sumA
+= src
[k
][ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1237 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1238 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1239 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1240 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1247 convolve_sep_replicate(GLint srcWidth
, GLint srcHeight
,
1248 const GLfloat src
[][4],
1249 GLint filterWidth
, GLint filterHeight
,
1250 const GLfloat rowFilt
[][4],
1251 const GLfloat colFilt
[][4],
1254 const GLint halfFilterWidth
= filterWidth
/ 2;
1255 const GLint halfFilterHeight
= filterHeight
/ 2;
1258 for (j
= 0; j
< srcHeight
; j
++) {
1259 for (i
= 0; i
< srcWidth
; i
++) {
1264 for (m
= 0; m
< filterHeight
; m
++) {
1265 for (n
= 0; n
< filterWidth
; n
++) {
1266 GLint is
= i
+ n
- halfFilterWidth
;
1267 GLint js
= j
+ m
- halfFilterHeight
;
1271 else if (is
>= srcWidth
)
1275 else if (js
>= srcHeight
)
1277 k
= js
* srcWidth
+ is
;
1278 sumR
+= src
[k
][RCOMP
] * rowFilt
[n
][RCOMP
] * colFilt
[m
][RCOMP
];
1279 sumG
+= src
[k
][GCOMP
] * rowFilt
[n
][GCOMP
] * colFilt
[m
][GCOMP
];
1280 sumB
+= src
[k
][BCOMP
] * rowFilt
[n
][BCOMP
] * colFilt
[m
][BCOMP
];
1281 sumA
+= src
[k
][ACOMP
] * rowFilt
[n
][ACOMP
] * colFilt
[m
][ACOMP
];
1284 dest
[j
* srcWidth
+ i
][RCOMP
] = sumR
;
1285 dest
[j
* srcWidth
+ i
][GCOMP
] = sumG
;
1286 dest
[j
* srcWidth
+ i
][BCOMP
] = sumB
;
1287 dest
[j
* srcWidth
+ i
][ACOMP
] = sumA
;
1295 _mesa_convolve_1d_image(const GLcontext
*ctx
, GLsizei
*width
,
1296 const GLfloat
*srcImage
, GLfloat
*dstImage
)
1298 switch (ctx
->Pixel
.ConvolutionBorderMode
[0]) {
1300 convolve_1d_reduce(*width
, (const GLfloat (*)[4]) srcImage
,
1301 ctx
->Convolution1D
.Width
,
1302 (const GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
1303 (GLfloat (*)[4]) dstImage
);
1304 *width
= *width
- (MAX2(ctx
->Convolution1D
.Width
, 1) - 1);
1306 case GL_CONSTANT_BORDER
:
1307 convolve_1d_constant(*width
, (const GLfloat (*)[4]) srcImage
,
1308 ctx
->Convolution1D
.Width
,
1309 (const GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
1310 (GLfloat (*)[4]) dstImage
,
1311 ctx
->Pixel
.ConvolutionBorderColor
[0]);
1313 case GL_REPLICATE_BORDER
:
1314 convolve_1d_replicate(*width
, (const GLfloat (*)[4]) srcImage
,
1315 ctx
->Convolution1D
.Width
,
1316 (const GLfloat (*)[4]) ctx
->Convolution1D
.Filter
,
1317 (GLfloat (*)[4]) dstImage
);
1326 _mesa_convolve_2d_image(const GLcontext
*ctx
, GLsizei
*width
, GLsizei
*height
,
1327 const GLfloat
*srcImage
, GLfloat
*dstImage
)
1329 switch (ctx
->Pixel
.ConvolutionBorderMode
[1]) {
1331 convolve_2d_reduce(*width
, *height
,
1332 (const GLfloat (*)[4]) srcImage
,
1333 ctx
->Convolution2D
.Width
,
1334 ctx
->Convolution2D
.Height
,
1335 (const GLfloat (*)[4]) ctx
->Convolution2D
.Filter
,
1336 (GLfloat (*)[4]) dstImage
);
1337 *width
= *width
- (MAX2(ctx
->Convolution2D
.Width
, 1) - 1);
1338 *height
= *height
- (MAX2(ctx
->Convolution2D
.Height
, 1) - 1);
1340 case GL_CONSTANT_BORDER
:
1341 convolve_2d_constant(*width
, *height
,
1342 (const GLfloat (*)[4]) srcImage
,
1343 ctx
->Convolution2D
.Width
,
1344 ctx
->Convolution2D
.Height
,
1345 (const GLfloat (*)[4]) ctx
->Convolution2D
.Filter
,
1346 (GLfloat (*)[4]) dstImage
,
1347 ctx
->Pixel
.ConvolutionBorderColor
[1]);
1349 case GL_REPLICATE_BORDER
:
1350 convolve_2d_replicate(*width
, *height
,
1351 (const GLfloat (*)[4]) srcImage
,
1352 ctx
->Convolution2D
.Width
,
1353 ctx
->Convolution2D
.Height
,
1354 (const GLfloat (*)[4])ctx
->Convolution2D
.Filter
,
1355 (GLfloat (*)[4]) dstImage
);
1364 _mesa_convolve_sep_image(const GLcontext
*ctx
,
1365 GLsizei
*width
, GLsizei
*height
,
1366 const GLfloat
*srcImage
, GLfloat
*dstImage
)
1368 const GLfloat
*rowFilter
= ctx
->Separable2D
.Filter
;
1369 const GLfloat
*colFilter
= rowFilter
+ 4 * MAX_CONVOLUTION_WIDTH
;
1371 switch (ctx
->Pixel
.ConvolutionBorderMode
[2]) {
1373 convolve_sep_reduce(*width
, *height
,
1374 (const GLfloat (*)[4]) srcImage
,
1375 ctx
->Separable2D
.Width
,
1376 ctx
->Separable2D
.Height
,
1377 (const GLfloat (*)[4]) rowFilter
,
1378 (const GLfloat (*)[4]) colFilter
,
1379 (GLfloat (*)[4]) dstImage
);
1380 *width
= *width
- (MAX2(ctx
->Separable2D
.Width
, 1) - 1);
1381 *height
= *height
- (MAX2(ctx
->Separable2D
.Height
, 1) - 1);
1383 case GL_CONSTANT_BORDER
:
1384 convolve_sep_constant(*width
, *height
,
1385 (const GLfloat (*)[4]) srcImage
,
1386 ctx
->Separable2D
.Width
,
1387 ctx
->Separable2D
.Height
,
1388 (const GLfloat (*)[4]) rowFilter
,
1389 (const GLfloat (*)[4]) colFilter
,
1390 (GLfloat (*)[4]) dstImage
,
1391 ctx
->Pixel
.ConvolutionBorderColor
[2]);
1393 case GL_REPLICATE_BORDER
:
1394 convolve_sep_replicate(*width
, *height
,
1395 (const GLfloat (*)[4]) srcImage
,
1396 ctx
->Separable2D
.Width
,
1397 ctx
->Separable2D
.Height
,
1398 (const GLfloat (*)[4]) rowFilter
,
1399 (const GLfloat (*)[4]) colFilter
,
1400 (GLfloat (*)[4]) dstImage
);
1410 * This function computes an image's size after convolution.
1411 * If the convolution border mode is GL_REDUCE, the post-convolution
1412 * image will be smaller than the original.
1415 _mesa_adjust_image_for_convolution(const GLcontext
*ctx
, GLuint dimensions
,
1416 GLsizei
*width
, GLsizei
*height
)
1418 if (ctx
->Pixel
.Convolution1DEnabled
1420 && ctx
->Pixel
.ConvolutionBorderMode
[0] == GL_REDUCE
) {
1421 *width
= *width
- (MAX2(ctx
->Convolution1D
.Width
, 1) - 1);
1423 else if (ctx
->Pixel
.Convolution2DEnabled
1425 && ctx
->Pixel
.ConvolutionBorderMode
[1] == GL_REDUCE
) {
1426 *width
= *width
- (MAX2(ctx
->Convolution2D
.Width
, 1) - 1);
1427 *height
= *height
- (MAX2(ctx
->Convolution2D
.Height
, 1) - 1);
1429 else if (ctx
->Pixel
.Separable2DEnabled
1431 && ctx
->Pixel
.ConvolutionBorderMode
[2] == GL_REDUCE
) {
1432 *width
= *width
- (MAX2(ctx
->Separable2D
.Width
, 1) - 1);
1433 *height
= *height
- (MAX2(ctx
->Separable2D
.Height
, 1) - 1);