Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** ppmio.c - Read / Write routines for PPM files */ #include /* Read header part of PPM file * * Input parameters: * FILE*

image text in transcribedimage text in transcribed

/** ppmio.c - Read / Write routines for PPM files */ #include

/* Read header part of PPM file * * Input parameters: * FILE* f - an open PPM file * * Output parameters: * int* width - width of the image, in pixels * int* height - height of the image, in pixels */ void read_header(FILE* f, int *width, int *height) { char buffer[256]; int rv;

fscanf(f, "%s", buffer); // magic (discard) fscanf(f, "%d %d", width, height); // image dimensions fscanf(f, "%d", &rv); // colour table size (discard) }

/* Write header part of PPM file * * Input Parameters: * FILE* f - an open PPM file * int width - width of the image, in pixels * int height - height of the image, in pixels */ void write_header(FILE* f, int width, int height) { fprintf(f, "P3 "); // magic fprintf(f, "%d %d ", width, height); // image dimensions fprintf(f, "255 "); // colour table size }

/* Read pixel (colour) data from PPM file * * Input parameters: * FILE* f - an open PPM file * int width - width of the image, in pixels * int height - height of the image, in pixels * * Output parameters: * int red[][] - 2D array containing red colour channel data * int green[][] - 2D array containing green colour channel data * int blue[][] - 2D array containing blue colour channel data * * Returns: * 0 if everything is ok * non-zero otherwise */ int read_ppm(FILE* f, int width, int height, int red[height][width], int green[height][width], int blue[height][width] ) {

// Add code to read in a PPM file

return 1; // FIXME }

/* Write pixel (colour) data to a PPM file * * Input parameters: * FILE* f - an open PPM file * int width - width of the image, in pixels * int height - height of the image, in pixels * int red[][] - 2D array containing red colour channel data * int green[][] - 2D array containing green colour channel data * int blue[][] - 2D array containing blue colour channel data */ void write_ppm(FILE* f, int width, int height, int red[height][width], int green[height][width], int blue[height][width] ) {

// Add code to write the PPM file }

PPM file I/O You will need to develop functions that load and save PPM files. PPM files have a header portion and a data portion. Reading and writing the header is already done for you in read header) and write_header ). You will develop the functions necessary to load and save the pixel data. Reading a PPM file Open ppmio. C. Look at the function read-ppm(). The arguments to this function are: PPM file I/O You will need to develop functions that load and save PPM files. PPM files have a header portion and a data portion. Reading and writing the header is already done for you in read header) and write_header ). You will develop the functions necessary to load and save the pixel data. Reading a PPM file Open ppmio. C. Look at the function read-ppm(). The arguments to this function are

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions