Created
December 28, 2010 10:20
-
-
Save DRMacIver/757116 to your computer and use it in GitHub Desktop.
ppm-reader.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <netpbm/pam.h> | |
#include <stdbool.h> | |
#include <stdint.h> | |
int main(int argc, char **argv){ | |
int c; | |
while((c = getc(stdin)) != EOF){ | |
ungetc(c, stdin); | |
struct pam inpam; | |
tuple *tuplerow; | |
unsigned int row; | |
pm_init(argv[0], 0); | |
pnm_readpaminit(stdin, &inpam, PAM_STRUCT_SIZE(tuple_type)); | |
tuplerow = pnm_allocpamrow(&inpam); | |
for(row = 0; row < inpam.height; row++){ | |
unsigned int column; | |
pnm_readpamrow(&inpam, tuplerow); | |
for(column = 0; column < inpam.width; ++column){ | |
// Process pixels in here however you want. | |
// This is a pointer to inpam.depth many long values | |
// inpam.depth seems to always be 3 for ffmpeg output, but I wouldn't swear that's always true | |
unsigned long *pixel = tuplerow[column]; | |
} | |
} | |
pnm_freepamrow(tuplerow); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i $1 -f image2pipe -vcodec ppm pipe:1 | ppm-reader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment