Answered step by step
Verified Expert Solution
Link Copied!

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
1 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 P3. 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 P3, then we know it's not a PPM fileUne 2 contains two numbers which are the width and height of the image (in that order). In the example above, the image is 3 pixels wide and 2 pixels high.
Line 3 contains the number 255 which is called the color depth, which is the maximum value for the red, green, and blue components of a pixel color
Lines 4 and 5 are the data section of this PPIM file. Since this image is 3 pixels wide and 2 pixels high the total number of poxels is 6. And since each pixel is saved as three integers (RGB triplet), there is a total of 18 integers in the data section. In the example above, the first row contains three pixels that have colors red (255,0,0), green (0,255,0), and blue (0,0,255). The second row has yellow (255,255,0). white (255.255.255), and black (0,0,0) pixels
To decode a PPM file, we follow these steps in sequence:
Read a line from the file and make sure it says P3
Read an integer from the file (call it w, the width).
Read another integer from the file (call it h, the height)
Read another integer from the file (call it d, the color depth)
Create a canvas with the given width and height.
For each row 1(from 0 to h-1)
For each columnj (from 01o w-1)
Read an integer r.
Read an integer 9
Read an integer b
Set the pixel color at coordinates (0.9)10(255.d,255.gd,255.5d)
2 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 P3 on a line.
Write the image's width and height on the following line.
Write the number 255 on the following line.
For each row i (from 0 to h-1):
For each columnj (from 0 to w-1)
Gel the pixel at coordinates (0.1) 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.
3 Interface and Implementation of Codecs
The following is the interface for ImageCodec (coder/decoder)The 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 1s 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.
image text in transcribed

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

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions