Question: you can read task from the image.i need to help to fix my code. I have two ppm files image 1 and image 2 i
you can read task from the image.i need to help to fix my code. I have two ppm files image and image i need to merge these files and image should be shown top right corner of the image i am pasting my code. In my code mergeImage.ppm created but only display image and nothing show image on the right corner of image you can use any image and show me the output ppm image please.i need to see output and fix my code please I worked on it for last hours
#include
#include
#include
#include
#include
#include
#define BUFFSIZE
Function to read and write PPM files using system calls
void mergeppmconst char file const char file const char outfile
int fd fd outfd;
ssizet bytesread, byteswritten;
char bufBUFFSIZE;
Open input files
fd openfile ORDONLY;
if fd
perrorError opening first file";
exit;
fd openfile ORDONLY;
if fd
perrorError opening second file";
exit;
Open output file
outfd openoutfile OWRONLY OCREAT OTRUNC, ;
if outfd
perrorError opening output file";
exit;
Read and write the first PPM file
while bytesread readfd buf, BUFFSIZE
byteswritten writeoutfd buf, bytesread;
if byteswritten bytesread
perrorWrite error";
exit;
Calculate the position to start writing the second image topright corner
lseekoutfd SEEKSET; Move to the beginning of the output file
lseekoutfd SEEKCUR; Skip the P header
Read the width and height of the first image
int width height;
readoutfd buf, BUFFSIZE;
sscanfbufd d &width &height;
Read the maximal value of color components
readoutfd buf, BUFFSIZE;
Move to the position to start writing the second image topright corner
lseekoutfd width height SEEKSET;
Read and write the second PPM file to the topright corner of the first file
while bytesread readfd buf, BUFFSIZE
byteswritten writeoutfd buf, bytesread;
if byteswritten bytesread
perrorWrite error";
exit;
Close all files
closefd;
closefd;
closeoutfd;
Function to check PPM file dimensions
void checkdimensionsconst char file const char file
int fd fd;
char bufBUFFSIZE;
ssizet bytesread;
int width height width height;
Open and read first PPM file
fd openfile ORDONLY;
if fd
perrorError opening first file";
exit;
bytesread readfd buf, BUFFSIZE;
closefd;
Parse width and height from the first file
sscanfbufP
d d
d
&width &height;
Open and read second PPM file
fd openfile ORDONLY;
if fd
perrorError opening second file";
exit;
bytesread readfd buf, BUFFSIZE;
closefd;
Parse width and height from the second file
sscanfbufP
d d
d
&width &height;
Check dimensions
if width width height height
fprintfstderr "Error: Dimensions of the first image are smaller than the second image.
;
exit;
int mainint argc, char argv
if argc
fprintfstderr "Usage: s
argv;
exit;
Check dimensions of the PPM files
checkdimensionsargv argv;
Merge the PPM files
mergeppmargv argv argv;
printfImages merged successfully into s
argv;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
