This page does not represent the most current semester of this course; it is present merely as an archive.
This assignment is really more about making sure you are ready for those that follow than it is an actual assignment. It is dramatically easier than HW1.
Unlike other assignments
This assignment is due the second week of class (i.e., 4 Sep or thereabouts) but earlier = better.
This and the following three assignments all work as follows:
Each file will have a number of lines; each line will have a keyword first, followed by zero or more extra pieces of information separated by whitespace (some mix of ' '
and '\t'
). Lines should be read in order, first to last, because some lines refer to the lines above them.
Ignore blank lines and lines starting with anything other than a keyword you know. Always strip leading and trailing space from a line before parsing it.
In this assignment input files might look like
png 200 300 outfilename.png
xy 10 20
xyrgb 50 50 255 127 0
ignore this line since "ignore" is not a keyword you know
likewise, ignore this line, which also starts with an unknown keyword
xyc 150 250 #ff00ee
You do not need to have error checking code. For example, if a png
keyword is not followed by exactly two positive integers and one string ending .png
, your code is welcome to break in any way you wish.
You will create an 8-bit RGBA PNG image with a specified width and height.
You could use libpng, but you don’t want to. The public-domain miniz.c header is sufficient for writing files (but not reading them, so it won’t help with texture mapping or the default HW5 project). I’ve posted a stripped-down version and an example interface to it.
Alternatively, a previous TAs suggested CImg and an example file cimg_example.cpp. I have not used CImg myself.
A more recent student suggestion was LodePNG, which has decent documentation on its own site.
If you find another library you like, let me know and I’ll see if I can easily get it on my compiling test server.
Remember, if you use a C-language header (like libpng or miniz) but are writing C++, you’ll need to put an extern "C" { ... }
block around the #include
The testing server currently runs clang 6.0. gcc 8.2 is also installed and can be switched to if a version compatibility issue is identified.
The relevant class is System.Drawing.Bitmap
, along with it’s setPixel
and save
methods
// ... set width, height, etc.
= new Bitmap(width, height, PixelFormat.Format32bppArgb);
Bitmap img .SetPixel(x,y, Color.FromARGB(r,g,b,a));
img.save("filename.png"); img
The testing server currently runs mono 5.14.
There are several image libraries in the D community; imageformats
works well.
import imageformats;
void main() {
// ... set width, height, etc.
auto img = new ubyte[width*height*4];
[(x + y*width)*4 .. (x + y*width + 1)*4] = [r,g,b,a];
img("filename.png", width, height, img, ColFmt.RGBA);
write_png}
Before imageformats
was a thing, I wrote minipng.d for my first version of this course. I doesn’t have many options, but it is simple to use; see the header comments for other uses.
import minipng;
void main() {
// ... set width, height, etc.
auto img = Img!ubyte(width, height);
[x,y] = [r,g,b,a];
img("filename.png");
img.save}
The testing server currently runs rdmd 2.081. dub, dmd, and ldc are also installed and can be switched to if a version compatibility issue is identified.
The relevant libraries are BufferedImage
and WritableRaster
from java.awt.image
and ImageIO
from javax.imageio
package. Do not use java.awt.Graphics
.
// ... set width, height, etc.
BufferedImage b = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
WritableRaster wr = b.getRaster();
int[] color = {r, g, b, a};
.setPixel(x, y, color);
wrImageIO.write(b, "png", new File("filename.png"));
The testing server currently runs javac 1.10.
The relevant library is pillow. To install, do pip install pillow
or pip3 install pillow
from the command line.
The typical import is from PIL import Image
. Do not use the ImageDraw
module.
# ... set width, height, etc.
= Image.new("RGBA", (width, height), (0,0,0,0))
img
# slow way:
img.im.putpixel((x,y), (r,g,b,a))
# not quote as slow way:
= img.im.putpixel # do once only
putpixel # repeat as needed
putpixel((x,y), (r,g,b,a))
"filename.png") img.save(
The testing server currently runs python 3.7.0. pypy 3.5.3 is also installed and can be switched to if a version compatibility issue is identified.
Want another language added? Let me know so I can build my grading harness for it.
Every file will begin with a line png
followed by two positive integers, width and height, and a filename. You should write a RGBA png image of the specified width and height (see Image file creation). You should write the file in the default directory. The initial color of every pixel in the image should be transparent black (0, 0, 0, 0).
You may assume the filename contains only non-whitespace ASCII characters and already has the appropriate .png
ending.
You may assume that png will always be the first valid keyword in the file.
Fill the pixel noted by the x and y coordinate to be opaque white (255, 255, 255, 255). xy 0 0
should fill the top left corner pixel. If the image is 200 wide and 300 tall, then xy 199 299
would fill the bottom right pixel.
You may assume x and y are integers within the image bounds.
Fill the pixel noted by the x and y coordinate to have the specified color (r, g, b, 255).
You may assume r, g, and b are integers between 0 and 255, inclusive. See the discussion of xy
for comments on x and y.
Fill the pixel noted by the x and y coordinate to have the specified color. The color is given in a web-standard 3-byte hex code: #rrggbb
, where rr
is a two-digit hexidecimal value for red, gg
for green, and bb
for blue. Set the alpha to 255 (0xff)
You may assume hexColorString is always a seven-character string of the appropriate format. See the discussion of xy
for comments on x and y.
Input file hw0ex1.txt:
png 5 8 hw0ex1.png
xy 0 1
xyrgb 1 2 127 255 255
xyc 2 3 #aaaaff
xy 3 4
xyrgb 4 5 200 120 3
xyrgb 3 3 0 0 0
xyrgb 2 4 0 0 0
should produce this image file: . That’s so small it’s almost impossible to see, so let’s zoom in and put a striped background behind the image so you can tell the difference between transparent and white:
The submission site for this assignment (only) will run automated tests and add information about their outcomes to the submission file list. There may be a small delay before it is visible, as we queue each submission as it comes in. Feel free to re-submit until you get positive status results. Please refer questions to piazza or professor office hours.