Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Image Application In C (http://www.go4expert.com/forums/image-application-c-t7828/)

bigbee 13Dec2007 15:53

Image Application In C
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?


Salem 13Dec2007 16:12

Re: Image Application In C
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.

bigbee 13Dec2007 17:45

Re: Image Application In C
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 ?

Salem 13Dec2007 18:06

Re: Image Application In C
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.

bigbee 13Dec2007 19:06

Re: Image Application In C

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++)

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?

Salem 13Dec2007 21:07

Re: Image Application In C
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.

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.

bigbee 13Dec2007 21:31

Re: Image Application In C
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
250............................................... ....RR GG BB 00.

bigbee 13Dec2007 21:34

Re: Image Application In C
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?

Salem 14Dec2007 04:02

Re: Image Application In C

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

bigbee 14Dec2007 04:40

Re: Image Application In C
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....

All times are GMT +5.5. The time now is 17:34.