[AD] getpixel error

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

I'm trying to use getpixel(), and getr(), getg(), getb(), but getpixel() is returning 1 or -1. What's this?

here my code:

#include <allegro.h>
#include <stdio.h>

void start_allegro(){

    allegro_init();

}

int main(){

    int x,y;
    char save[99];
    FILE *out;

    typedef struct{
        int r;
        int g;
        int b;
    } rgb;
   
    start_allegro();

    BITMAP *imagem = load_bitmap("picture.bmp", NULL);

    int matrizPixel[imagem->h][imagem->w];
    rgb matrizRgb[imagem->h][imagem->w];

    printf("2 - Digite o caminho para o arquivo a ser salvo: ");
               scanf("%s",&save);          
               if((((out = fopen(save,"w")) == NULL))){
                      system("clear");
                      printf("ERROR");
                      sleep(3000);
                      return;
               }
               else{
       
                            for(x = 0; x < imagem->h; x++)
                                for(y = 0; y < imagem->w; y++){
                                    matrizPixel[x][y] = getpixel(imagem, x, y);
                                   
                                }

                            for(x = 0; x < imagem->h; x++)
                                for(y = 0; y < imagem->w; y++){
                                    matrizRgb[x][y].r = getr(matrizPixel[x][y]);
                                    matrizRgb[x][y].g = getg(matrizPixel[x][y]);
                                    matrizRgb[x][y].b = getb(matrizPixel[x][y]);
                                    fprintf(out,"pix x=%d y=%d, r=%d,g=%d,b=%d\n",x,y,matrizPixel[x][y],matrizRgb[x][y].r,matrizRgb[x][y].g,matrizRgb[x][y].b);
                                }
                           fprintf(out,"\n\n ACABOU PUTEDO!!!!!");
                           fclose(out);
                           system("clear");
                           }
    destroy_bitmap(imagem);
    return 0;
}
END_OF_MAIN()

-----------------------------

few lines of the log.

pix x=0 y=0, r=1,g=0,b=0
pix x=0 y=1, r=1,g=0,b=0
pix x=0 y=2, r=1,g=0,b=0
pix x=0 y=3, r=1,g=0,b=0
pix x=0 y=4, r=1,g=0,b=0
pix x=0 y=5, r=1,g=0,b=0
pix x=0 y=6, r=1,g=0,b=0
pix x=0 y=7, r=1,g=0,b=0
pix x=0 y=8, r=1,g=0,b=0
pix x=0 y=9, r=1,g=0,b=0
pix x=0 y=10, r=1,g=0,b=0
pix x=0 y=11, r=1,g=0,b=0
pix x=0 y=12, r=1,g=0,b=0
pix x=0 y=13, r=1,g=0,b=0
pix x=0 y=14, r=1,g=0,b=0
pix x=0 y=15, r=1,g=0,b=0
pix x=0 y=16, r=1,g=0,b=0
pix x=0 y=17, r=1,g=0,b=0

and sometimes r=-1

What's my error?



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/