Ejemplo n.º 1
0
  /**
   * Construct a fully transparent image <tt>bounds</tt> size, will paint one tile with paint. Thus
   * paint should not be a pattered paint or gradient but should be a solid color.
   *
   * @param bounds the bounds of the image (in fact will respond with any request).
   */
  public FloodRed(Rectangle bounds, Paint paint) {
    super(); // We _must_ call init...

    ColorModel cm = GraphicsUtil.sRGB_Unpre;

    int defSz = AbstractTiledRed.getDefaultTileSize();

    int tw = bounds.width;
    if (tw > defSz) tw = defSz;
    int th = bounds.height;
    if (th > defSz) th = defSz;

    // fix my sample model so it makes sense given my size.
    SampleModel sm = cm.createCompatibleSampleModel(tw, th);

    // Finish initializing our base class...
    init((CachableRed) null, bounds, cm, sm, 0, 0, null);

    raster = Raster.createWritableRaster(sm, new Point(0, 0));
    BufferedImage offScreen = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);

    Graphics2D g = GraphicsUtil.createGraphics(offScreen);
    g.setPaint(paint);
    g.fillRect(0, 0, bounds.width, bounds.height);
    g.dispose();
  }
Ejemplo n.º 2
0
  /**
   * This function 'fixes' the source's sample model. right now it just ensures that the sample
   * model isn't much larger than my width.
   */
  protected static SampleModel fixSampleModel(CachableRed src, Rectangle bounds) {
    int defSz = AbstractTiledRed.getDefaultTileSize();

    SampleModel sm = src.getSampleModel();
    int w = sm.getWidth();
    if (w < defSz) w = defSz;
    if (w > bounds.width) w = bounds.width;
    int h = sm.getHeight();
    if (h < defSz) h = defSz;
    if (h > bounds.height) h = bounds.height;

    // System.out.println("Pad SMSz: " + w + "x" + h);

    return sm.createCompatibleSampleModel(w, h);
  }
Ejemplo n.º 3
0
  /**
   * This function 'fixes' the source's sample model. right now it just ensures that the sample
   * model isn't much larger than my width.
   */
  protected SampleModel fixSampleModel(CachableRed src, ColorModel cm, Rectangle bounds) {
    SampleModel sm = src.getSampleModel();
    int defSz = AbstractTiledRed.getDefaultTileSize();

    int w = sm.getWidth();
    if (w < defSz) w = defSz;
    if (w > bounds.width) w = bounds.width;
    int h = sm.getHeight();
    if (h < defSz) h = defSz;
    if (h > bounds.height) h = bounds.height;

    if ((w <= 0) || (h <= 0)) {
      w = 1;
      h = 1;
    }

    return cm.createCompatibleSampleModel(w, h);
  }