Image Application In C

bigbee's Avatar, Join Date: Dec 2007
Go4Expert Member
Hi All,

I am doing a project ,where i have to display a image read from the RAM! and its Game data and is in .bin format.
As on now i have read the bin datat but i am stuck right now in arranging the data as per the need.

Well i have read 240000 words ......now i have to put that data into a pixel map....Like one word is one pixel.

And i have to achieve that in 320 rows and 250 coloums...I have used fread to read the data and store the data in a array....

Can anybody provide any reference or any resources?

BB

Last edited by shabbir; 13Dec2007 at 17:54.. Reason: Confine links to signature
0
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
320 * 250 = 80,000
80,000 * 3 = 240,000

It's highly likely that you have 3 bytes per pixel, which typically means 1 byte Red, 1 byte Green and 1 byte Blue.

So read 3 bytes, construct a pixel with that RGB value and plot it on screen using whatever graphical API you have to hand.
0
bigbee's Avatar, Join Date: Dec 2007
Go4Expert Member
Thanks for ur Calculation!
Well i am using Tcl libraries for that.....But my problem is not with arranging the data!
My , buf[i] in programs contains all the data! Whatever u calculted,
Now i have to position them in row coloumn....How? Can u suggest me some examples or ?
0
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
Unless you post an attempt, we can't begin to figure out exactly what you're looking at.

To me it just seems a simple case of stepping through the array 3 bytes at a time for 80,000 pixels.
Every 320 pixels, you start a new row of pixels.
0
bigbee's Avatar, Join Date: Dec 2007
Go4Expert Member
Code:
if((stream = fopen(argv[1],"rb" ))!= NULL )
    {
      numread = fread(buf,sizeof(int),size,stream );
      fclose( stream );       
      printf( "Number of items read = %d\n", numread );
 	    for (k = 0; k < size; k++)
	      {
               printf(FORMAT,buf[k]);
	      }
	}
Where size = 240000 and FORMAT is int.
And infact i should read 4 bytes and the 4th byte being a zero ......So i have used as it is.
Now the buf contains 80000 pixels. Its just a part of the read,
So now can u figure it out?

Last edited by shabbir; 13Dec2007 at 20:50.. Reason: Code block
0
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
Well assuming that int is 4 bytes, and each pixel takes 3 bytes, then the pixel data is all confused, and you have more work to extract the information.

Here's what 4 pixels looks like spread over 3 int's.
RR GG BB RR : GG BB RR GG : BB RR GG BB


If you have a buff of 240000 chars, and not 80000 ints, then you might get somewhere.

But then, is the raw file 240000 bytes or 320000 bytes?
Because that would tell you whether it used 4-byte pixels with every 4th byte being zero.
0
bigbee's Avatar, Join Date: Dec 2007
Go4Expert Member
no buf is also int !
so i think no problem until its reading ....Please can u tell how to jump to next row when 320 pixel i sover...I have declared the buf as int! ...and actually the file is much more bigger and i have eliiminated some border towards the bottom...and changed the program which generates the data ....as per this ....so
1 ... RR GG BB 00 : : RR GG BB 00 .................. 320
321.............................
.
..
250............................................... ....RR GG BB 00.
0
bigbee's Avatar, Join Date: Dec 2007
Go4Expert Member
Actually this is finished in TclTk....:But not optimized!!
So F*** my Boss........ have to do !! and not very good in C also!

Do u know that also ??
k well now how can continue?
0
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
Code:
int row, col, pos = 0;
for ( row = 0 ; row < 250 ; row++ ) {
  for ( col = 0 ; col < 320 ; col++ ) {
    // do stuff with buff[pos], plot pixel at row,col
    pos++;
  }
}
0
bigbee's Avatar, Join Date: Dec 2007
Go4Expert Member
Thanks ...

Anyways i will try it on monday and tell you the result...
I am out of work!

But i think the pos should be compared with the size ....i hope ok anyways thanks again..

Get back to you....