Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C and FILE I/O => separate ascii from binary

binary ascii

  • Please log in to reply
5 replies to this topic

#1 denarced

denarced

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 181 posts

Posted 15 December 2008 - 12:19 AM

So,
file is opened in mode "rb".
First, in ppm there is header, which is ascii and after that, in P6 format, there's binary pixeldata. Question becomes, how do I know when header ends and pixeldata begins ??
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 15 December 2008 - 04:26 AM

Do you have control over what is a valid file format? Normally you'll have a fixed number of characters of ASCII text or a delimiter at the end of the ASCII text.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 denarced

denarced

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 181 posts

Posted 15 December 2008 - 04:57 AM

wouldn't appear to be so
at least ascii-latin are accepted in header
but than again usually the maximum pixel value is 255 and anything below that is ok so there lies the problem
no perticular set of characters as far as I understand it

delimiter

in the header the only delimiter is 0A is hex so thats 10 and that
s '\n'
this does not help either
I'm thinking
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 15 December 2008 - 08:35 AM

Most documented file formats will have either a fixed number of characters, a delimiter, or some other indicator so you know where the end of the "header" info is.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 denarced

denarced

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 181 posts

Posted 15 December 2008 - 12:01 PM

Most documented file formats will have either a fixed number of characters, a delimiter, or some other indicator so you know where the end of the "header" info is.


makes sense
  • 0

#6 Lance

Lance

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 270 posts

Posted 15 December 2008 - 03:40 PM

PPM file format

A PPM file consists of a sequence of one or more PPM images. There are no data, delimiters, or padding before, after, or between images.

Each PPM image consists of the following:

1. A "magic number" for identifying the file type. A ppm image's magic number is the two characters "P6".
2. Whitespace (blanks, TABs, CRs, LFs).
3. A width, formatted as ASCII characters in decimal.
4. Whitespace.
5. A height, again in ASCII decimal.
6. Whitespace.
7. The maximum color value (Maxval), again in ASCII decimal. Must be less than 65536 and more than zero.
8. A single whitespace character (usually a newline).
9. A raster of Height rows, in order from top to bottom. Each row consists of Width pixels, in order from left to right. Each pixel is a triplet of red, green, and blue samples, in that order. Each sample is represented in pure binary by either 1 or 2 bytes. If the Maxval is less than 256, it is 1 byte. Otherwise, it is 2 bytes. The most significant byte is first.

A row of an image is horizontal. A column is vertical. The pixels in the image are square and contiguous.
10. In the raster, the sample values are "nonlinear." They are proportional to the intensity of the ITU-R Recommendation BT.709 red, green, and blue in the pixel, adjusted by the BT.709 gamma transfer function. (That transfer function specifies a gamma number of 2.2 and has a linear section for small intensities). A value of Maxval for all three samples represents CIE D65 white and the most intense color in the color universe of which the image is part (the color universe is all the colors in all images to which this image might be compared).

ITU-R Recommendation BT.709 is a renaming of the former CCIR Recommendation 709. When CCIR was absorbed into its parent organization, the ITU, ca. 2000, the standard was renamed. This document once referred to the standard as CIE Rec. 709, but it isn't clear now that CIE ever sponsored such a standard.

Note that another popular color space is the newer sRGB. A common variation on PPM is to subsitute this color space for the one specified.
11. Note that a common variation on the PPM format is to have the sample values be "linear," i.e. as specified above except without the gamma adjustment. pnmgamma takes such a PPM variant as input and produces a true PPM as output.
12. Strings starting with "#" may be comments, the same as with PBM.
...
  • 0





Also tagged with one or more of these keywords: binary, ascii

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download