Image Application In C

Discussion in 'C' started by bigbee, Dec 13, 2007.

  1. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Dec 13, 2007
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    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.
     
  3. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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 ?
     
  4. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    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.
     
  5. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Dec 13, 2007
  6. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    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.
     
  7. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  8. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  9. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    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++;
      }
    }
    
     
  10. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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....
     
  11. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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]
     
    Last edited by a moderator: Dec 18, 2007
  12. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    Maybe post the code that you ran?
    What you posted isn't even close to being able to compile, let alone run.
     
  13. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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!!!
     
  14. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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,
     
    Last edited by a moderator: Dec 19, 2007
  15. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    bigbee, Please read [thread]168[/thread] for how to post code in the posts
     
  16. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Shabbir!!! Infact i forgot to do that! Was thinking and pressed submit.....I didnt find way to reedit it..So !!
    :)
     
  17. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     
  18. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Made that to 10 and soon you should see that you are able to edit your posts.
     
  19. bigbee

    bigbee New Member

    Joined:
    Dec 13, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Ok..!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice