reading pixels from y frame (yuv frame) using fread()?

This is a discussion on reading pixels from y frame (yuv frame) using fread()? within the C Programming forums, part of the General Programming Boards category; hi..i would like to know to read pixels and later store the pixel values in arrays..do i use fread()? if ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    1

    reading pixels from y frame (yuv frame) using fread()?

    hi..i would like to know to read pixels and later store the pixel values in arrays..do i use fread()? if yes how? this is a part of my code..please reply ASAP...thank you
    .
    .
    .
    Code:
    fseek(vidf, 0L, SEEK_SET); //same as rewind(vidf)
       //initialize array
       for(k=0;k<256;k++){
            inityHist[k]=0;
            }
       fseek(vidf,(54+4*256),SEEK_SET);
    
          for(rowpixels=0;rowpixels<height;rowpixels++){
            for(colpixels=0; colpixels<width; colpixels++){
               fread(ttemp, sizeof(char), 1, vidf);
               
    			grayscaleV = *ttemp;
                inityHist[grayscaleV] = inityHist[grayscaleV] + 1; //to check the ocurences of pixel
                totalPixels++;
                }
          }
    .
    .
    .
    Last edited by Salem; 09-17-2006 at 05:35 AM. Reason: Added code tags - please learn to use them

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    All things being equal, like ttemp pointing at some valid memory, and say the file opened with "rb" mode, and the initial fseek offset being OK, it should be fine.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    This stuff is interesting me. I would like to know how this is working out. Do you have to use a pointer to the video memory? I don't get that:
    Code:
    fseek(vidf,(54+4*256),SEEK_SET);
    Is this supposed to point on pixel memory? Is this in a file?

    I'm all mixed up.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Since fseek sets the file position in a file, I'd guess it seeks (54+4*256) characters from the beginning of the file (SEEK_SET). http://www.cppreference.com/stdio/fseek.html

    [edit] sizeof(char) is always 1, but you can leave it in if you want to. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading words using fread
    By -EquinoX- in forum C Programming
    Replies: 22
    Last Post: 05-05-2008, 02:09 PM
  2. reading BMP files and pixels' colours
    By Xavier in forum C++ Programming
    Replies: 3
    Last Post: 12-16-2005, 04:19 AM
  3. fread - reading strings and integers.
    By Vber in forum C Programming
    Replies: 1
    Last Post: 11-17-2002, 03:08 PM
  4. Replies: 1
    Last Post: 06-06-2002, 04:17 PM
  5. fread is reading too much
    By CeeCee in forum C Programming
    Replies: 7
    Last Post: 02-18-2002, 02:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21