Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Having trouble with a few sections. Im just looking for in main.c - void put_ima

ID: 3534623 • Letter: H

Question

Having trouble with a few sections. Im just looking for

in main.c -
void put_image(char message[], imageType *img);
in image.c -
void write_image(FILE *out_file, imageType *img);
void write_pixel(FILE *out_file, pixelType p);

image.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"image.h"
//==================================================================
void read_pixel(FILE *in_file, pixelType *p)
{
/* If you read as characters, then you have to type cast to
* unsigned char. A conversion issue.

char r,g,b;
fscanf(in_file,"%c",&r);
fscanf(in_file,"%c",&g);
fscanf(in_file,"%c",&b);

p->red = (unsigned char) r;
p->green = (unsigned char) g;
p->blue = (unsigned char) b;
*/
//A BETTER WAY - use the %hhc in the write_pixel function
fscanf(in_file,"%hhc",&p->red);
fscanf(in_file,"%hhc",&p->green);
fscanf(in_file,"%hhc",&p->blue);

}

//==================================================================
void read_image(FILE *in_file, imageType *img)
{
char newLineChar;

//Please note when a newLineChar is read. Reason: need to be ready
//for the next item at the beginning of the line. To be consistent,
//it's read everytime and discarded. Due to the nature of scanf
//you really only need it while reading the magicNumber and maxColor
fscanf(in_file,"%[^ ]%c",img->magicNumber,&newLineChar);
fscanf(in_file,"%[^ ]%c",img->comment,&newLineChar);
fscanf(in_file,"%d%d%c",&img->width,&img->height,&newLineChar);
fscanf(in_file,"%d%c",&img->maxColor,&newLineChar);

for(int i=img->height-1;i>=0; i--)
for(int j=0; j<img->width; j++)
read_pixel(in_file, &img->image[i][j]);
}

//==================================================================
void write_pixel(FILE *out_file, pixelType p)
{
?
}

//==================================================================
void write_image(FILE * out_file, imageType *img)
{
?
}

//==================================================================
pixelType cvt_pixel_bw(pixelType orig_p)
{
unsigned char r,g,b;
unsigned char bw;
pixelType new_p;

r = orig_p.red;
g = orig_p.green;
b = orig_p.blue;
bw = (unsigned char)(r*RED_BW_WEIGHT+g*GREEN_BW_WEIGHT+b*BLUE_BW_WEIGHT);
new_p.red = new_p.green = new_p.blue = bw;
return new_p;
}
//==================================================================
void cvt_bw(imageType *orig_img, imageType *new_img)
{
strcpy(new_img->magicNumber, orig_img->magicNumber);
strcpy(new_img->comment,orig_img->comment);
new_img->width = orig_img->width;
new_img->height = orig_img->height;
new_img->maxColor = orig_img->maxColor;
for(int i=new_img->height-1;i>=0; i--)
for(int j=0; j<new_img->width; j++) {
new_img->image[i][j] = cvt_pixel_bw(orig_img->image[i][j]);
}
}

main.c


#include<stdlib.h>
#include<stdio.h>

#include"image.h"

void get_image(const char message[], imageType *img);
void put_image(const char message[], imageType *img);

int main()
{
imageType orig_image;
imageType new_image;

char type[2];

printf("========================== ");
printf(" Image filtering ");
printf("========================== ");
printf(" Options ");
printf("(c)olor to Black and White ");
printf("========================== ");
printf("Enter one of the above: ");
scanf("%1s",type);
while (type[0] != 'c') {
printf("Invalid input! ");
printf("Options: (c)olor ");
scanf("%1s",type);
}

//since all filters operator on an original image....
//open file, read in original image, one at a time, and then close the file.
get_image("original",&orig_image);

if(type[0] == 'c') {
cvt_bw(&orig_image, &new_image);
}

put_image("new",&new_image);
return 0;
}

void get_image(const char message[], imageType *img)
{
FILE *infile;

char image_filename[30];
//open file, read in image, then close the file.
printf("Enter the %s image filename (no spaces): ",message);
scanf("%s",image_filename);
infile=fopen(image_filename,"r");
if(infile==NULL) {
fprintf(stderr,"Error with %s image file: ",message);
fprintf(stderr,"%s ",image_filename);
exit(1);
}
read_image(infile, img);
fclose(infile);
}

void put_image(const char message[], imageType *img)
{
not sure what goes here
}






Explanation / Answer

what do you actually want??? as the output??


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote