用实际代码调用函数

时间:2009-10-03 22:29:40

标签: c

我正在尝试做的是接受此函数调用...

assign_sum_to_pixel(&current_pixel, sum);

并将其替换为它所调用的实际代码...

/* 
 * 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; 

}

我想出的是......

/*
 * 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;

    }
    }
}

但......出于某些原因,当我运行代码时,它无法正常工作,从而导致我出现此错误

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

这是我添加新代码的地方......

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);    
有人可以告诉我,如果我做错了什么......我错过了某个地方的括号吗?我没有正确初始化变量吗?返回不应该在底部等于dst[RIDX(i, j, dim)]任何帮助,评论,建议将不胜感激。谢谢。

3 个答案:

答案 0 :(得分:4)

不要手工内联。 Use the inline keyword或更好,让编译器决定。

答案 1 :(得分:3)

您的current_pixelpixel,而之前您传递了&current_pixelpixel *(指向像素的指针)。所以,你现在需要使用current_pixel.red(带点), current_pixel->red(带有“向右箭头”),左手需要一个指针箭的一面;等等。

答案 2 :(得分:0)

如果你必须强制内联,你最好使用宏

#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)

然后将其用作

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);
    ...

至少这样,代码在源代码中保持分离。