read PPM file and store it in an array; coded with C

前端 未结 2 1641
野的像风
野的像风 2020-12-02 19:46

I need to read a PPM file and store it in an array written in C. Can anybody help me out doing this?

Thanks a lot.

2条回答
  •  無奈伤痛
    2020-12-02 20:11

    Here is the PPM specification.

    The PPM file is built in 9 sections separated by white-spaces.

    • Open the file
    • read until the first white space and check you got P6. Then skip other white-spaces.
    • read until the next white space, convert your buffer to an integer width. Then skip other white-spaces
    • read until the next white space, convert your buffer to an integer height. Then skip other white-spaces
    • Allocate a 2D array of integers in the size of height*width
    • read the max-val
    • read line by line and fill the array

提交回复
热议问题