Reputation: 179
I am trying to scale the color components of a pixel. To do this I am creating a new pixel where each color component is the original value * the scaling factor for that color. The resulting pixel must have values that fall within the range of 0 <= color <= 255
.
This is what I am doing so far
public class ColorScale implements Transformer {
/* This part creates a transformer that scales the color in each pixel by the following factors
parameter r0 = red factor
parameter b0 = blue factor
parameter g0 = green factor
*/
public ColorScale(double r0, double g0, double b0) {
// need guidance as what to do here
}
public Pixel transformPixel(pixel p) {
return p;
}
}
More info is here: http://www.seas.upenn.edu/~cis120/current/hw/hw07/javadoc/ColorScale.html
I am new to Java, so I just need guidance as to what to do in the ColorScale function.
Upvotes: 1
Views: 841
Reputation: 6073
From the JavaDoc you provided, ColorScale
is one of the Transformer
implementations.
From your code snippet:
public ColorScale(double r0, double g0, double b0) {
// need guidance as what to do here
}
This is the constructor. You are creating an instance
of a specific implementation of a Pixel Transformer
(in this case, ColorScale
).
The constructor should simply set the internal state of the Transformer
, and then it will be set up for transforming Pixels via the contract method transformPixel
.
In other words,
public ColorScale(double r0, double g0, double b0) {
// Set internal state fields.
this.r0 = r0;
this.g0 = g0;
this.b0 = b0;
}
Upvotes: 3