tags:

views:

138

answers:

3

what I'm trying to do is take this function call...

assign_sum_to_pixel(&current_pixel, sum);

and replace it with the actual code that it calls which is this...

/* 
 * assign_ sum_ to_ pixel - Computes averaged pixel value in current_pixel 
 */


static void assign_ sum_ to_ pixel (pixel *current_ pixel, pixel_ sum sum) 

{

    current_ pixel->red = (unsigned short) (sum.red/sum.num);
    current_ pixel->green = (unsigned short) (sum.green/sum.num);
    current_ pixel->blue = (unsigned short) (sum.blue/sum.num);
    return; 

}

What I came up with was this...

/*
 * mysmooth1 - my smooth1 
 */


char mysmooth1_descr[] = "my smooth1: My smooth1";

void mysmooth1(int dim, pixel *src, pixel *dst)

{

    int i, j;
    int ii, jj;
    pixel_ sum sum;
    pixel current_ pixel;

    for (i = 0; i < dim; i++)
    for (j = 0; j < dim; j++)
    {
    initialize_ pixel_ sum (&sum);
    for(ii = max(i-1, 0); ii <= min(i+1, dim-1); ii++) 
    for(jj = max(j-1, 0); jj <= min(j+1, dim-1); jj++) 
        accumulate_ sum(&sum, src[RIDX(ii, jj, dim)]);
    {
    ***current_ pixel->red = (unsigned short) (sum.red/sum.num);
    current_ pixel->green = (unsigned short) (sum.green/sum.num);
    current_ pixel->blue = (unsigned short) (sum.blue/sum.num);***    


    ***(These three lines above are the lines I inserted which is where the function call use to be)***

    dst[RIDX(i, j, dim)] = return;

    }
    }
}

but...for some reason when I run the code it fails to work giving me this error

kernels.c:456: error: invalid type argument of â->â

kernels.c:457: error: invalid type argument of â->â

kernels.c:458: error: invalid type argument of â->â

kernels.c:459: warning: statement with no effect

which is right where I added the new code ...

current_ pixel->red = (unsigned short) (sum.red/sum.num);

current_ pixel->green = (unsigned short) (sum.green/sum.num);

current_ pixel->blue = (unsigned short) (sum.blue/sum.num);

can someone tell me if I'm doing something wrong... Am I missing brackets somewhere? am I not initializing my variables correctly? is return not supposed to be at the bottom equaling to dst[RIDX(i, j, dim)] any help, comments, suggestions would be greatly appreciated. Thank You.

+4  A: 

Don't inline by hand. Use the inline keyword or better, let the compiler decide.

e-t172
This is more of a comment, not an answer.
GMan
This is an answer, not a comment. +1
Ira Baxter
It's sound advice, not an answer. These kind of answers belong at the end of a real answer, such as Alex's. If you asked a question about linked lists and somebody said, "Use an array" as an answer, would you consider it helpful? I wouldn't, even though it might be good advice. Help him with his code, and explain why functions should be left to be inlined by the compiler.
GMan
+3  A: 

Your current_pixel is a pixel, while previously you passed &current_pixel, a pixel * (pointer to pixel). So, you now need to use current_pixel.red (with a dot), not current_pixel->red (with a "right-pointing arrow"), which needs a pointer on the left hand side of the arrow; and so forth.

Alex Martelli
A: 

If you must force inlining, you'd be better off using a macro

#define ASSIGN_SUM_TO_PIXEL (current_pixel, sum)\
do {\
    current_pixel.red = (unsigned short) (sum.red/sum.num);\
    current_pixel.green = (unsigned short) (sum.green/sum.num);\
    current_pixel.blue = (unsigned short) (sum.blue/sum.num);\
} while(0)

then use it as

for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
{
initialize_pixel_sum (&sum);
for(ii = max(i-1, 0); ii <= min(i+1, dim-1); ii++) 
for(jj = max(j-1, 0); jj <= min(j+1, dim-1); jj++) 
    accumulate_sum(&sum, src[RIDX(ii, jj, dim)]);
{
    ASSIGN_SUM_TO_PIXEL (current_pixel, sum);
    ...

At least that way the code is kept separated in source.

Steve Gilham