Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( Java code ) PPM stands for Aortable Pixmap. Ifs a simple file format that can be used to save and retrieve digital image data
Java code PPM stands for Aortable Pixmap. Ifs a simple file format that can be used to save and retrieve digital image data from files and to transfer them between machines and operating systems. Unlike JPG PNG and GIF formats, PPM does not use any compression decompression schemes maling reading and writing PPM flies relatuely easier. For this assignment, we will simplify the PPM format further, dealing only with the essentials. For more details about PPM refer to the Wikipedia entry
Decoding PPM data
The contents of a sample PPM file is shown in the following box. It encodes information about a small imageThe PPM file is divided into two sections. a header section the first three lines and a data section everything that follows the header The frst line of a PPM fie always contains the characters P This is called the file's magic number and is used to distinguish files of different types. If the first line does not contain the characters P then we know it's not a PPM fileUne contains two numbers which are the width and height of the image in that order In the example above, the image is pixels wide and pixels high.
Line contains the number which is called the color depth, which is the maximum value for the red, green, and blue components of a pixel color
Lines and are the data section of this PPIM file. Since this image is pixels wide and pixels high the total number of poxels is And since each pixel is saved as three integers RGB triplet there is a total of integers in the data section. In the example above, the first row contains three pixels that have colors red green and blue The second row has yellow white and black pixels
To decode a PPM file, we follow these steps in sequence:
Read a line from the file and make sure it says P
Read an integer from the file call it the width
Read another integer from the file call it h the height
Read another integer from the file call it the color depth
Create a canvas with the given width and height.
For each row from to
For each columnj from o w
Read an integer
Read an integer
Read an integer
Set the pixel color at coordinates
Encoding PPM Data
Encoding is the process of saving an image data to a PPM file. To do this, we follow these steps in sequence:
Open the file for writing.
Write P on a line.
Write the image's width and height on the following line.
Write the number on the following line.
For each row i from to :
For each columnj from to
Gel the pixel at coordinates of the image
Wirite the red, green, and blue numbers, separated by spaces
If we're at the last column in the row, print a newline character. Otherwise, print a space.
Flush the file's output.
Interface and Implementation of Codecs
The following is the interface for ImageCodec coderdecoderThe method decode takes an input stream containing image data, and retums a mutable image containing the decoded image. The method encode takes an image and an output strearn and prints the image data into the output stream. The method load is like decode except that it takes a fie name from witich the data s toaded. The method sove, similarty, saves the image data to a flleWrite the class PPMCodec that implements imageCodec. It must encode and decode the streams according to the specifications listed in this assignment.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started