This is a laplace transform for filter.c

I can't demonstrate that it does the same as the previous laplace filter
as the previous filter always crashed Camorama with my webcam because of
errors in the arithmetic.

This was previously sent to package maintainer as a replacement filter.c
for 0.17-3.


void laplace (unsigned char *image, int z, int x, int y)
{
    int i,j,k;
    unsigned char *image2;
        
    image2 = (unsigned char *) malloc (sizeof (unsigned char) * x * y * z);
    memcpy (image2, image, x * y * z);

    /*
     * Laplace filter is based on having an 3 x 3 arrays, the central
     * point is multipled by 8 and the surrounding 8 values subtracted.
     *
     */

    /* Let's ignore the edges and corners */

    for ( i = 1 ; i < (y - 1) ; i++ ) {
      for ( j = 1 ; j < (x - 1) ; j++) {
        for ( k = 0 ; k < z ; k++) {

          image2[ (i * x + j ) * z  + k ] =
            image[ ( (i-1) * x + (j-1)) * z + k ] +
            image[ ( (i-1) * x + (j  )) * z + k ] +
            image[ ( (i-1) * x + (j+1)) * z + k ] +
            image[ ( (i  ) * x + (j-1)) * z + k ] +
            image[ ( (i  ) * x + (j+1)) * z + k ] +
            image[ ( (i+1) * x + (j-1)) * z + k ] +
            image[ ( (i+1) * x + (j  )) * z + k ] +
            image[ ( (i+1) * x + (j+1)) * z + k ] ;

        }
      }
    }

    for ( i = 1 ; i < (y - 1) ; i++ ) {
      for ( j = 1 ; j < (x - 1) ; j++) {
        for ( k = 0 ; k < z ; k++) {
          if (image[ (i * x + j ) * z + k ] * 8 > image2[ (i * x + j ) * z + k 
]){
            image[ (i * x + j ) * z + k ] =
              8 * image[ (i * x + j ) * z + k ] -  image2[ (i * x + j ) * z + k 
];
          } else {
             image[ (i * x + j ) * z + k ] = 0;
          }
        }
      }
    }


    free (image2);
}



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to