13.07.2015 Views

Manual de Apoio 2010

Manual de Apoio 2010

Manual de Apoio 2010

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

glConvolutionFilter2D (int target , int internalFormat ,int width , int height ,int format , int type ,Buffer image );Em que o target toma o valor GL2.GL CONVOLUTION 2D, o internalFormat indica o formato interno danossa matriz <strong>de</strong> convolução (para o nosso caso GL2.GL RGB), width/height especificam o tamanho da matriz,format indica o formato dos pixels na imagem <strong>de</strong> <strong>de</strong>stino, type especifica o tipo <strong>de</strong> dados da imagem e imagecontém a informação da imagem.Gaussian BlurPara aplicar o efeito <strong>de</strong> gaussian blur (Figura 7.6) po<strong>de</strong>mos utilizar a seguinte matriz <strong>de</strong> convolução:⎛1 2 1⎞⎝ 2 4 2 ⎠1 2 1Para tal utilizamos o seguinte código:// Matriz ( convolution kernel ) para efectuar gaussian blurfloat norm = 16f; // normalizacao : somatorio dos valores da matrizFloatBuffer mGaussian = FloatBuffer . wrap ( new float [] {1f/norm , 2f/norm , 1f/norm ,2f/norm , 4f/norm , 1f/norm ,1f/norm , 2f/norm , 1f/ norm});// Aplicar a matrizgl. glConvolutionFilter2D (GL2 . GL_CONVOLUTION_2D , GL2 . GL_RGB , 3, 3,GL2 . GL_LUMINANCE , GL2 . GL_FLOAT , mGaussian);// Activar convolucao 2Dgl. glEnable ( GL2 . GL_CONVOLUTION_2D );// Mostrargl. glDrawPixels (img . getWidth () , img . getHeight () ,img . getGLFormat () , GL2 . GL_UNSIGNED_BYTE , bb );// Desactivar convolucao 2Dgl. glDisable ( GL2 . GL_CONVOLUTION_2D );Figura 7.6: Gaussian BlurA forma <strong>de</strong> aplicar outras matrizes é semelhante. Apenas mudamos o último argumento da funçãoglConvolutionFilter2D <strong>de</strong> mGaussian para a matriz criada. Como tal interessa apenas referir quais asmatrizes utilizadas e como foram inicializadas.75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!