javalib.worldimages
Class RasterImage

java.lang.Object
  extended by javalib.worldimages.AImage
      extended by javalib.worldimages.RasterImage
All Implemented Interfaces:
Drawable, WorldImage, tester.ISame<WorldImage>
Direct Known Subclasses:
FreezeImage, FromFileImage, FromURLImage

public class RasterImage
extends AImage

An image stored explicitly in raster form.

Version:
Dec. 25, 2012
Author:
Stephen Bloch

Field Summary
static AffineTransform id
           
protected  BufferedImage rendering
           
(package private) static Color transparent
           
 
Fields inherited from interface javalib.worldimages.WorldImage
LOOKS_SAME
 
Constructor Summary
protected RasterImage()
          Default constructor so subclasses can start without a rendering and fill it in later.
protected RasterImage(BufferedImage rendering)
          Constructor that takes in an already-rendered image.
 
Method Summary
static WorldImage build(int width, int height, ImageBuilder b, Object extra)
           
 void draw(Graphics2D g)
          Draw this image in the provided Graphics2D context.
 boolean equals(Object other)
          Is this the same as another WorldImage, as expression trees? Define this at every level that has instance variables.
 RasterImage frozen()
          If it's already a RasterImage, that's good enough.
 int getBottom()
          Produce the bottom of the bounding box.
 Color getPixelColor(int x, int y)
          Get the color of a specified pixel of an image.
 int getRight()
          Produce the bottom of the bounding box.
 int hashCode()
          Get a hash code for the WorldImage.
(package private) static RasterImage make(BufferedImage rendering)
          Pseudo-constructor.
 WorldImage map(ImageMap b, Object extra)
          Create a rectangular image pixel by pixel from an existing image.
protected  void renderIfNecessary()
          make sure rendering isn't null
 boolean save(String filename)
          Save a WorldImage to a .png file.
protected  void setRendering(BufferedImage rendering)
          Setter so subclasses can fill in the rendering later.
 String toIndentedString(String indent)
          Produce a String that represents this image, indented by the given indent.
 
Methods inherited from class javalib.worldimages.AImage
above, aboveCentered, beside, besideCentered, build, centerMoved, centerMoved, cornerString, cropped, getCenter, getHeight, getLeft, getTop, getWidth, isApplet, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeFromFile, makeFromURL, makeImage, makeLine, makeLine, makeLine, makePolygon, makePolygon, makePolygon, makePolygon, makePolygon, makePolygon, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, map, moved, moved, normalized, overlay, overlayCentered, overlayImages, overlayXY, place, rotate, rotated, rotated, rotatedAround, rotatedAround, rotatedInPlace, rotatedInPlace, same, sameClass, scaled, scaled, show, toString, xReflected, yReflected
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

public static final AffineTransform id

rendering

protected BufferedImage rendering

transparent

static final Color transparent
Constructor Detail

RasterImage

protected RasterImage()
Default constructor so subclasses can start without a rendering and fill it in later.


RasterImage

protected RasterImage(BufferedImage rendering)
Constructor that takes in an already-rendered image.

Parameters:
rendering -
Method Detail

build

public static WorldImage build(int width,
                               int height,
                               ImageBuilder b,
                               Object extra)

draw

public void draw(Graphics2D g)
Description copied from interface: WorldImage
Draw this image in the provided Graphics2D context.

Parameters:
g - the provided Graphics2D context

equals

public boolean equals(Object other)
Description copied from interface: WorldImage
Is this the same as another WorldImage, as expression trees? Define this at every level that has instance variables.

Specified by:
equals in interface WorldImage
Overrides:
equals in class AImage
Parameters:
other - the object to compare with this
Returns:
true iff the images are isomorphic expression trees, with equal fields.

frozen

public RasterImage frozen()
If it's already a RasterImage, that's good enough.

Specified by:
frozen in interface WorldImage
Overrides:
frozen in class AImage
Returns:
a RasterImage that memoizes the rendering of this image

getBottom

public int getBottom()
Description copied from interface: WorldImage
Produce the bottom of the bounding box.

Returns:
the y coordinate of the bottom of the bounding box

getPixelColor

public Color getPixelColor(int x,
                           int y)
Description copied from interface: WorldImage
Get the color of a specified pixel of an image.

Specified by:
getPixelColor in interface WorldImage
Overrides:
getPixelColor in class AImage
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the Color of the specified pixel.

getRight

public int getRight()
Description copied from interface: WorldImage
Produce the bottom of the bounding box.

Returns:
the x coordinate of the right edge of the bounding box

hashCode

public int hashCode()
Description copied from interface: WorldImage
Get a hash code for the WorldImage. Needs to agree with equals(). In our case, "equals" means they're the same as expression trees.

Specified by:
hashCode in interface WorldImage
Overrides:
hashCode in class Object

make

static RasterImage make(BufferedImage rendering)
Pseudo-constructor.

Parameters:
rendering -

map

public WorldImage map(ImageMap b,
                      Object extra)
Description copied from interface: WorldImage
Create a rectangular image pixel by pixel from an existing image.

Specified by:
map in interface WorldImage
Overrides:
map in class AImage
Parameters:
b - an ImageMap encapsulating a function from Color to Color
extra - an arbitrary addtional argument to pass to the function
Returns:
a new image the same size and shape as this

renderIfNecessary

protected void renderIfNecessary()
make sure rendering isn't null


save

public boolean save(String filename)
Description copied from interface: WorldImage
Save a WorldImage to a .png file.

Specified by:
save in interface WorldImage
Overrides:
save in class AImage
Returns:
true if the file was saved successfully.

setRendering

protected void setRendering(BufferedImage rendering)
Setter so subclasses can fill in the rendering later.

Parameters:
rendering -

toIndentedString

public String toIndentedString(String indent)
Description copied from interface: WorldImage
Produce a String that represents this image, indented by the given indent.

Define this in all concrete subclasses.

Convention: The result of toIndentedString() will neither begin nor end with a newline; the specified indent will immediately follow each internal newline.

Parameters:
indent - the given prefix representing the desired indentation
Returns:
the String representation of this image