|
|
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [WM]: loading image & reading the pixel values
Rajan,
In a project I did few years ago, I had to read .bmp files in VC++. I wrote a code that read the pixel values. But later since I
wanted to implement it on 32-bit TI DSP board, I compressed each 4 pixel values in a 32-bit. You can find the code below. To get
read of the compression, just change width/4 to width and read and store one pixel in a variable. I hope it helps. Let me know if
you want the whole program. It opens a window and asks you to choose your .bmp file and you can browse and find it, and it loads the
image.
Maneli
--------------------------------------------------------------------------
clock_t start, end;
FILE *stream1;
unsigned long int **data;
unsigned long int *buffer;
unsigned char *byteBuff;
unsigned char header[54+4*256];
int numread;
if ((stream1 = fopen( fileName, "rb" )) == NULL)
{
MessageBox( "File could not be opened" );
getch();
exit(2);
}
// Reading hearder of Bitmap file
numread = fread( header, sizeof(unsigned char ),(54+4*256), stream1 );
if (header[0]!='B' && header[1]!='M')
{
MessageBox("Not a BMP file");
getch();
exit(2);
}
// int
sizeOfFile=header[2]+header[3]*256+header[4]*(256*256)+header[5]*(256*256*256);
// Computing width of Image
int
width=header[18]+header[19]*256+header[20]*(256*256)+header[21]*(256*256*256);
// Computing height of Image
int
height=header[22]+header[23]*256+header[24]*(256*256)+header[25]*(256*256*256);
// int
imageSize=header[34]+header[35]*256+header[36]*(256*256)+header[37]*(256*256*256);
// int
compression=header[30]+header[31]*256+header[32]*(256*256)+header[33]*(256*256*256);
int
offset=header[10]+header[11]*256+header[12]*(256*256)+header[13]*(256*256*256);
// Allocating memory for Image Data
data=new unsigned long int *[height];
for (int a=0;a<height; a++)
data[a]=new unsigned long int [width/4];
buffer=new unsigned long int[4];
byteBuff= new unsigned char[4];
for (int x1=(height-1);x1>=0;x1--)
{
for (int y1=0; y1<width/4; y1++)
{
// Reading intensity of 4 pixel of Image
numread=fread(&byteBuff[0], sizeof(unsigned char),4, stream1 );
// Checking if data has been read
if (numread==0)
{
MessageBox("All of file haven't been read");
getch();
exit(2);
}
for (int b=0;b<4;b++)
buffer[b]=(unsigned long int)byteBuff[b];
// Storing the intensity of 4 pixel in a 32 bits variable
// Just to conform with the algoritm used in the DSP card program
buffer[1]=buffer[1]<<8;
buffer[2]=buffer[2]<<16;
buffer[3]=buffer[3]<<24;
buffer[0]=((buffer[0]|buffer[1])|(buffer[2]|buffer[3]));
data[x1][y1]=buffer[0];
}
}
fclose(stream1);
> hi friends
>
> can anyone help me in developing a code for loading the .bmp image and
> reading the pixel values in VC++
>
> can anyone send me the code for it in VC++ / java or the link where i
> can find it
>
> i need the pixel values for the DCT algorithm to process the image..
>
> thanking you in advance
>
> waiting.........
> rajan
______________________________________________________________________________
Watermarking Mailing List - http://www.watermarkingworld.org/ml.html
To unsubscribe send email to "majordomo@watermarkingworld.org" with
"unsubscribe watermarking YOURMAIL" in the body.
______________________________________________________________________________
|