CS 345: Spring 2025
Programming Assignment 3
Round and round we go
We generalize colors to an object (GShader) and add a matrix to the canvas.
class GShader {
public:
virtual ~GShader() {}
virtual bool isOpaque() = 0;
virtual bool setContext(const GMatrix& ctm) = 0;
virtual void shadeRow(int x, int y, int count, GPixel row[]) = 0;
};
std::shared_ptr<GShader> GCreateBitmapShader(const GBitmap&, const GMatrix&);
class GMatrix {
public:
GMatrix();
static GMatrix Translate(float tx, float ty);
static GMatrix Scale(float sx, float sy);
static GMatrix Rotate(float radians);
static GMatrix Concat(const GMatrix& secundo, const GMatrix& primo);
std::optional invert() const;
void mapPoints(GPoint dst[], const GPoint src[], int count) const;
...
};
class GCanvas {
public:
virtual void save() = 0;
virtual void restore() = 0;
virtual void concat(const GMatrix&) = 0;
...
};
You task is to extend the subclass of GCanvas you created in PA3, subclass GShader, and implement GMatrix.
- Implement the missing methods on GMatrix.
- Implement save() restore() and concat() on your GCanvas subclass.
- Subclass GShader to implement the GCreateBitmapShader() factory.
- Implement GDrawSomething() to exercise matrices and shaders.
The pa3 directory should like something like this:
- apps contains the code for testing your code.
- expected contains sample output from the image tool to compare with your output.
- include contains class headers that your code can use.
- src contains common implementations needed for the tools.
- DO NOT EDIT/ADD/REMOVE anything in these sub-directories. You should only add files to the root of the directory.
- your_files any .cpp or .h files you need for your implementation. All of your work must be here.
To test your code...
> make
> ./image -e expected
> ./tests
> ./dbench
> ./bench
Bench scores on the VM
clear 2.54
rects_blend 6.34
rects_opaque 0.75
rect_big 0.53
rect_tiny 0.52
quads_blend 6.87
quads_opaque 1.08
circles_large 3.51
circles_tiny 0.52
modes_0 1.43
modes_x 24.73
modes_1 15.05
bitmap_opaque 3.37
bitmap_alpha 6.61