Ask C/C++ Expert


Home >> C/C++

FIT 3042 System Tools and
Programming Languages
Semester 1 2013
Assignment 1
An SDL video player for a custom video format
Worth: 20% of final mark.
Must be completed individually
Hurdle: 40% of assignment marks across assignment 1&2.
Due: Monday 29th April 2013, 5PM.
In this project you will implement a simple video player using the Simple DirectMedia Layer as
a display library.
The video files that the player is required to play will be in a custom format called DUMBRLE,
and are based on one of the simplest graphics compression schemes runlength
encoding.
Pixel maps
As you probably know, video images are made up of a collection of coloured dots or pixels.
To represent these digitally, we use a sequence of numbers representing the intensity of red,
green, and blue colouration of each pixel by
convention, that order is typically used. For
most video files, 8bit
integers are used to represent colour intensity, where 0 (the smallest
value that can be represented as an 8bit
unsigned integer) represents the lowest intensity,
and 255 the highest.
The table below shows some example colour values and the resulting colour:
Color values Colour
(0,0,0) XXXX (black)
(0, 255,0) XXXX (green)
(128, 128, 0) XXXX (vomit)
(255, 255, 255) (white)
To represent an entire image in a file, all we need to do is store a sequence of colour values
in a defined order, and supply a little bit of extra information about the image size and shape
(either explicitly or implicitly). One very simple format for doing so is the Portable PixMap
format, or PPM, used in the widelydistributed
netpbm image processing tools. There are
two versions of PPM one
encodes the numbers directly, the second writes the numbers as
ASCII text and is known as "plain PPM". A very small example plain PPM is below. The first
line is a "magic number" that identifies the file as a "plain PPM" file, the second line contains a
comment, the third line records the width and height of the image in pixels, and the last line
contains the maximum value for a "channel" (note that this example uses 15 rather than the
more common 255).
Pixels are represented in the file lefttoright,
then toptobottom
order
.
P3
# feep.ppm
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 0
We could write a video player that simply reads and displays a sequence of PPM files
sufficiently quickly. However, there are two problems with this: first, it''s kind of
inconvenient to have a video spread out over thousands, possibly hundreds of
thousands of individual files, and secondly the PPM format takes up a lot of space just
to store a single image.
RLE image compression
As far as the second problem goes, we can reduce this by taking advantage of a common
property of image data it
is very repetitive. We can take advantage of this property using a
simple scheme called runlength
encoding.
As Wikipedia1 explains:
1 Runlength
encoding. (2012, November 9). In Wikipedia, The Free Encyclopedia. Retrieved 04:08,
December 13, 2012, from
For example, consider a screen containing plain black text on a solid white
background. There will be many long runs of white pixels in the blank space, and
many short runs of black pixels within the text. Let us take a hypothetical single scan
line, with B representing a black pixel and W representing white:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
If we apply the runlength
encoding (RLE) data compression algorithm to the above
hypothetical scan line, we get the following:
12W1B12W3B24W1B14W
This is to be interpreted as twelve Ws, one B, twelve Ws, three Bs, etc.
The runlength
code represents the original 67 characters in only 18.
The runlength
encoding scheme we will use for our files is based on this principle, but is
slightly more sophisticated: the "PackBits Variant" scheme designed by Michael Dipperstein2.
Video File Format
Our video file format is unique. Like PPM, it contains some header information which
describes the dimensions of the frames that make up the images. It then contains data
representing each individual frame of the video.
To assist in the runlength
encoding, within each frame we will store the red channel for the
whole frame, then the green, then the blue. You should apply the PackBits algorithm to the
data for each channel, for each frame, independently.
A BackusNaur
form3 description of the file format is presented below:

::=

::=


::= "DUMBRLEv1\n"
::= " " "\n"
::=
::=

::= /* a positive integer rendered as an ASCII string */
::= | "E"
::= "K"

:: <
greenframedata><
blueframedata>

::
::

http://en.wikipedia.org/w/index.php?title=Runlength_
encoding&oldid=522223183
2
http://michael.dipperstein.com/rle/index.html
3
Add reference for BackausNaur
::

::
/* binary unsigned integers with variant PackBits
compression applied, see http://en.wikipedia.org/wiki/PackBits and
http://michael.dipperstein.com/rle/index.html*/

stores
the information for the red channel,
for the
green channel, and
for the blue channel. Each channel has an 8bit
value for
each pixel.
Each channel''s data is stored in rowmajor
order, so the first value corresponds to the top left of the
image, the second value the pixel immediately to the right, and so on, until you start the next row.
As noted, each channel''s data is compressed using "Variant PackBits" compression by Michael
Dipperstein.
There are a couple of sample DUMBRLE files, and in one case the PGM files from which it
was produced, on Moodle. There is also a Ubuntu package containing a tool,
ppmtodumbrle, which can compress a series of files in PPM format (all of the same size,
and with a maxval of 255) into a single dumbrle file.
to use it, you must first create a series of PPM files in the same directory using the following
naming convention:
xxxx.
ppm
Where prefix is a prefix common to all the files, and xxxx is a 4digit
integer 0000 up to
(potentially) 9999. The files must all be the same size.
To make a DUMBRLE file, run ppmtodumbrle as follows:
ppmtodumbrle outfile minindex
maxindex
Where outfile is the name for the output file, minindex
is the number of the first image in
the sequence you wish to convert, and maxindex
is the last.
Note that ppmtodumbrle has not been engineered properly, and will simply crash or
worse, fail silently, if the command line, if the input is illformed.
If you submit such a fragile
piece of code, you will be heavily marked down!
Simple DirectMedia Layer
The Simple DirectMedia Layer "is a crossplatform
multimedia library 4 designed to provide
low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D
video framebuffer". If it''s not already installed, you can install it on your virtual machine (you
will need the dev
package as well as the library itself).
4 http://www.libsdl.org
SDL
is extensively documented online, and there are many tutorials. As well as a 2D video
library, it provides support for event loops with timers, which may be useful for ensuring that
video frames are updated at the correct moments.
* SDL is introduced in Lectures 9&10.
Netpbm and libnetpbm
For stage 1, you may choose to use libnetpbm, a library that supports loading and saving
correctlyformed
PPM files. The PPM file format is very simple, so it is not really of that much
assistance. If you do, you should use the (very out of date, but functional) version included
with the Ubuntu distribution on the virtual machines.
Your Task
Your task is to implement a video player using SDL to play videos in the format described.
However, because the task is substantial, there are several incremental stages of
functionality that you should implement. Each stage builds on the previous one, and you
should share as much code as possible between them do
not do "cut and paste" reuse!
Furthermore, even if you complete stage 3, your submission should also build solutions for
stage 1 and 2 as well.
stage 1: maximum 10/20.
Implement a commandline
converter dumbrletoppm that converts a DUMBRLE file as
described above, into a series of PPM files.
dumbrletoppm takes two command line arguments: the first is the name of the DUMBRLE
file to convert, and the second is the prefix to be prepended to the output files. Each output
file should have xxxx.
ppm appended to it, where xxxx is a 4digit
integer indicating which
frame it is. The first frame should be 0001, the next 0002, and so on.
For instance, the following command
dumbrle2ppm stuff.dumbrle stuffout
If stuff.dumbrle is present and readable, and a correctly formed DUMBRLE file, this
should produce a sequence of files stuffout0001.
ppm, stuffout0002.
ppm and so
on.
stage 2: maximum 13/20
Implement a utility firstframeview that displays the first frame of a DUMBRLE file on the
screen. firstframeview should have two commandline
arguments, the first is the
name of the DUMBRLE file to be displayed, the second is the time (in seconds) for which the
frame is to be displayed before closing.
stage 3: maximum 17/20
Implement dumbrleplayer, which plays a DUMBRLE video using the SDL library.
dumbrleplayer has two commandline
arguments, the name of the file to be played, and
the delay (in milliseconds) between frames. Delays should not be allowed to accumulate a
50 frame video played with a delay of 20 should take 1 second to play! After the video has
finished playing, the program should close.
For example,
dumbrleplayer stuff.dumbrle 25
should play the DUMBRLE file stuff.dumbrle with each frame appearing at a 25
millisecond interval.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9623831

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As