Image Application In C

Go4Expert Member
13Dec2007,15:53   #1
bigbee's Avatar
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
Ambitious contributor
13Dec2007,16:12   #2
Salem's Avatar
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.
Go4Expert Member
13Dec2007,17:45   #3
bigbee's Avatar
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 ?
Ambitious contributor
13Dec2007,18:06   #4
Salem's Avatar
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.
Go4Expert Member
13Dec2007,19:06   #5
bigbee's Avatar
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
Ambitious contributor
13Dec2007,21:07   #6
Salem's Avatar
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.
Go4Expert Member
13Dec2007,21:31   #7
bigbee's Avatar
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.
Go4Expert Member
13Dec2007,21:34   #8
bigbee's Avatar
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?
Ambitious contributor
14Dec2007,04:02   #9
Salem's Avatar
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++;
  }
}
Go4Expert Member
14Dec2007,04:40   #10
bigbee's Avatar
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....