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
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.
Thanks for ur Calculation! Well i am using Tcl libraries for that.....But my problem is not with arranging the data! My , buf 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 ?
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.
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?
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.
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.
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?
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++; } }
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....
HI, Its giving a Segmentation Fault Can u see to it once? Code: Type = INT ROW = 320 COL = 250 FORMAT = %x TYPE *buf1[ROW][COL] if((stream = fopen(argv[1],"rb" ))!= NULL ) { numread = fread(buf1,sizeof(int),size,stream ); fclose( stream ); printf( "Number of items read = %d\n", numread ); if[(pos < 240000) { for(row=0;row<320;row++){ for(col=0;col<250;col++){ if (buf1[row][col] != 0) printf(FORMAT,buf1[pos]); pos++; } } } But how can i use the pos with reepect to total size? And i have declared buf1[row][col]
Maybe post the code that you ran? What you posted isn't even close to being able to compile, let alone run.
Ok i will post it tommorow morning ..do look at it once ....Actually i will post the complete which has someother stuff related to what i am doing! SO u can trim it out or i will try to trim only the part which i need!!!
Code: #include <tk.h> #include <tcl.h> #include "commands.h" #define TYPE int #define FORMAT "%8x" #define size 240000 #define ROW 320 #define COL 250 static void usage (void) { fprintf(stderr, "\ usage: Pacman FILE_NAME\n"); } int Tcl_Pacman(ClientData clientData, Tcl_Interp * interp, int argc , char *argv[]) { FILE *stream; int numread; TYPE *buf1[ROW][COL]; int i,j,k; int row, col, pos = 0; if (argc!= 2) { usage(); } if((stream = fopen(argv[1],"rb" ))!= NULL ) { numread = fread(buf1,sizeof(int),size,stream ); fclose( stream ); printf( "Number of items read = %d\n", numread ); if(pos < 240000) { for(row=0;row<320;row++){ for(col=0;col<250;col++){ if (buf1[row][col] != 0) printf(FORMAT,buf1[ROW][COL]); } } } else { printf( "File %s could not be opened\n",argv[1]); return 0; } } Well if you find any bracket missing or more...DO ignore it! And this is only the main part . Should i attach the bin file also which i have to read Regards,
Thanks Shabbir!!! Infact i forgot to do that! Was thinking and pressed submit.....I didnt find way to reedit it..So !!
You can re-edit the posts after you have 25 posts but as that is the problem many of us are facing and We are planning to get that number in single figure.