O
oswald.harry
hi
i am reading a set of jpeg files(RGB) and extracts the pixel values as
longs.i want to create a
2d array with numof rows=numof images and numof cols=numof pixels in
each image.ie each row of
the 2d array will represent an image.
I managed to get the imagedata using jpeg library of cygwin and it
stores the rgb values in array pointed to by unsigned char *image .and
i am able to get the rgb values for each pixel and pack them into a
long using a packrgb(...) function that does some bit shifting
long packrgb(int r,int g,int b){
int a;
a=255;
long res;
res=(255 << 24) | ((r & 0xff) << 16)|((g & 0xff) << 8)|(b &
0xff);
return res;
}
long * readrgbjpegfile(char* filename){
.....
/* using library i get values into unsigned char *image */
....
int imagearea=imagewidth* imgheight;/* is equal to num of pixels in
an image */
/* i take the r,g,b of each pixel pack it into long and store it in an
array */
long * imgpixels=malloc(imagearea*sizeof(imgpixels));
int r,g,b,index,pixval;
i=0;
index=0;
while(index<imagearea){
r=image[i++];
g=image[i++];
b=image[i++];
printf("r:%d,g:%d,b:%d\n",r,g,b);
pixval=packrgb(r,g,b);
printf("pixval:%d\n",pixval);
imgpixels[index]=pixval;
index++;
}
return imgpixels;
}
upto here i am getting the needed functionality..but i am not sure how
to go about creating the 2d array and set each row..i am not quite
sure about the memory allocation part too
any advise/help will be most welcome..also as a newbie i am not sure
if the above is the correct way of coding
thanx
oharry
i am reading a set of jpeg files(RGB) and extracts the pixel values as
longs.i want to create a
2d array with numof rows=numof images and numof cols=numof pixels in
each image.ie each row of
the 2d array will represent an image.
I managed to get the imagedata using jpeg library of cygwin and it
stores the rgb values in array pointed to by unsigned char *image .and
i am able to get the rgb values for each pixel and pack them into a
long using a packrgb(...) function that does some bit shifting
long packrgb(int r,int g,int b){
int a;
a=255;
long res;
res=(255 << 24) | ((r & 0xff) << 16)|((g & 0xff) << 8)|(b &
0xff);
return res;
}
long * readrgbjpegfile(char* filename){
.....
/* using library i get values into unsigned char *image */
....
int imagearea=imagewidth* imgheight;/* is equal to num of pixels in
an image */
/* i take the r,g,b of each pixel pack it into long and store it in an
array */
long * imgpixels=malloc(imagearea*sizeof(imgpixels));
int r,g,b,index,pixval;
i=0;
index=0;
while(index<imagearea){
r=image[i++];
g=image[i++];
b=image[i++];
printf("r:%d,g:%d,b:%d\n",r,g,b);
pixval=packrgb(r,g,b);
printf("pixval:%d\n",pixval);
imgpixels[index]=pixval;
index++;
}
return imgpixels;
}
upto here i am getting the needed functionality..but i am not sure how
to go about creating the 2d array and set each row..i am not quite
sure about the memory allocation part too
any advise/help will be most welcome..also as a newbie i am not sure
if the above is the correct way of coding
thanx
oharry