void createBufferedImage() {
    // REMIND:  Be careful!  Is this called everytime there is a
    // startProduction?  We only want to call it if it is new or
    // there is an error
    isDefaultBI = false;
    try {
      biRaster = cmodel.createCompatibleWritableRaster(width, height);
      bimage = createImage(cmodel, biRaster, cmodel.isAlphaPremultiplied(), null);
    } catch (Exception e) {
      // Create a default image
      cmodel = ColorModel.getRGBdefault();
      biRaster = cmodel.createCompatibleWritableRaster(width, height);
      bimage = createImage(cmodel, biRaster, false, null);
    }
    int type = bimage.getType();

    if ((cmodel == ColorModel.getRGBdefault())
        || (type == BufferedImage.TYPE_INT_RGB)
        || (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
      isDefaultBI = true;
    } else if (cmodel instanceof DirectColorModel) {
      DirectColorModel dcm = (DirectColorModel) cmodel;
      if (dcm.getRedMask() == 0xff0000
          && dcm.getGreenMask() == 0xff00
          && dcm.getBlueMask() == 0xff) {
        isDefaultBI = true;
      }
    }
  }
Ejemplo n.º 2
0
 /**
  * Converts an SWT ImageData to an AWT BufferedImage.
  *
  * @param bufferedImage
  * @return
  */
 @Override
 public BufferedImage getBufferedImage(ImageData data) {
   ColorModel colorModel = null;
   PaletteData palette = data.palette;
   if (palette.isDirect) {
     colorModel =
         new DirectColorModel(data.depth, palette.redMask, palette.greenMask, palette.blueMask);
     BufferedImage bufferedImage =
         new BufferedImage(
             colorModel,
             colorModel.createCompatibleWritableRaster(data.width, data.height),
             false,
             null);
     for (int y = 0; y < data.height; y++) {
       for (int x = 0; x < data.width; x++) {
         int pixel = data.getPixel(x, y);
         RGB rgb = palette.getRGB(pixel);
         bufferedImage.setRGB(x, y, rgb.red << 16 | rgb.green << 8 | rgb.blue);
       }
     }
     return bufferedImage;
   } else {
     RGB[] rgbs = palette.getRGBs();
     byte[] red = new byte[rgbs.length];
     byte[] green = new byte[rgbs.length];
     byte[] blue = new byte[rgbs.length];
     for (int i = 0; i < rgbs.length; i++) {
       RGB rgb = rgbs[i];
       red[i] = (byte) rgb.red;
       green[i] = (byte) rgb.green;
       blue[i] = (byte) rgb.blue;
     }
     if (data.transparentPixel != -1) {
       colorModel =
           new IndexColorModel(data.depth, rgbs.length, red, green, blue, data.transparentPixel);
     } else {
       colorModel = new IndexColorModel(data.depth, rgbs.length, red, green, blue);
     }
     BufferedImage bufferedImage =
         new BufferedImage(
             colorModel,
             colorModel.createCompatibleWritableRaster(data.width, data.height),
             false,
             null);
     WritableRaster raster = bufferedImage.getRaster();
     int[] pixelArray = new int[1];
     for (int y = 0; y < data.height; y++) {
       for (int x = 0; x < data.width; x++) {
         int pixel = data.getPixel(x, y);
         pixelArray[0] = pixel;
         raster.setPixel(x, y, pixelArray);
       }
     }
     return bufferedImage;
   }
 }
Ejemplo n.º 3
0
 SampleModel getRGBSampleModel() {
   rgbCM = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
   WritableRaster wr = rgbCM.createCompatibleWritableRaster(1, 1);
   SampleModel sampleModel = wr.getSampleModel();
   sampleModel = sampleModel.createCompatibleSampleModel(width, height);
   return sampleModel;
 }
 static synchronized WritableRaster makeRaster(ColorModel cm, Raster srcRas, int w, int h) {
   if (xrgbmodel == cm) {
     if (xrgbRasRef != null) {
       WritableRaster wr = (WritableRaster) xrgbRasRef.get();
       if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
         xrgbRasRef = null;
         return wr;
       }
     }
     // If we are going to cache this Raster, make it non-tiny
     if (w <= 32 && h <= 32) {
       w = h = 32;
     }
   } else if (argbmodel == cm) {
     if (argbRasRef != null) {
       WritableRaster wr = (WritableRaster) argbRasRef.get();
       if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
         argbRasRef = null;
         return wr;
       }
     }
     // If we are going to cache this Raster, make it non-tiny
     if (w <= 32 && h <= 32) {
       w = h = 32;
     }
   }
   if (srcRas != null) {
     return srcRas.createCompatibleWritableRaster(w, h);
   } else {
     return cm.createCompatibleWritableRaster(w, h);
   }
 }
Ejemplo n.º 5
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();

    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height),
              dstCM.isAlphaPremultiplied(),
              null);
    }
    WritableRaster dstRaster = dst.getRaster();

    int[] inPixels = getRGB(src, 0, 0, width, height, null);
    inPixels = filterPixels(width, height, inPixels, transformedSpace);
    setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);

    return dst;
  }
Ejemplo n.º 6
0
 /**
  * Returns a new <code>BufferedImage</code> using the same color model as the image passed as a
  * parameter. The returned image is only compatible with the image passed as a parameter. This
  * does not mean the returned image is compatible with the hardware.
  *
  * @param image the reference image from which the color model of the new image is obtained
  * @return a new <code>BufferedImage</code>, compatible with the color model of <code>image</code>
  */
 public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
   ColorModel cm = image.getColorModel();
   return new BufferedImage(
       cm,
       cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()),
       cm.isAlphaPremultiplied(),
       null);
 }
Ejemplo n.º 7
0
 public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
   if (dstCM == null) dstCM = src.getColorModel();
   return new BufferedImage(
       dstCM,
       dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()),
       dstCM.isAlphaPremultiplied(),
       null);
 }
Ejemplo n.º 8
0
  /**
   * Create a new ColorModel with it's alpha premultiplied state matching newAlphaPreMult.
   *
   * @param cm The ColorModel to change the alpha premult state of.
   * @param newAlphaPreMult The new state of alpha premult.
   * @return A new colorModel that has isAlphaPremultiplied() equal to newAlphaPreMult.
   */
  public static ColorModel coerceColorModel(ColorModel cm, boolean newAlphaPreMult) {
    if (cm.isAlphaPremultiplied() == newAlphaPreMult) return cm;

    // Easiest way to build proper colormodel for new Alpha state...
    // Eventually this should switch on known ColorModel types and
    // only fall back on this hack when the CM type is unknown.
    WritableRaster wr = cm.createCompatibleWritableRaster(1, 1);
    return cm.coerceData(wr, newAlphaPreMult);
  }
  /**
   * Returns a <code>BufferedImage</code> that supports the specified transparency and has a data
   * layout and color model compatible with this <code>GraphicsConfiguration</code>. This method has
   * nothing to do with memory-mapping a device. The returned <code>BufferedImage</code> has a
   * layout and color model that can be optimally blitted to a device with this <code>
   * GraphicsConfiguration</code>.
   *
   * @param width the width of the returned <code>BufferedImage</code>
   * @param height the height of the returned <code>BufferedImage</code>
   * @param transparency the specified transparency mode
   * @return a <code>BufferedImage</code> whose data layout and color model is compatible with this
   *     <code>GraphicsConfiguration</code> and also supports the specified transparency.
   * @throws IllegalArgumentException if the transparency is not a valid value
   * @see Transparency#OPAQUE
   * @see Transparency#BITMASK
   * @see Transparency#TRANSLUCENT
   */
  public BufferedImage createCompatibleImage(int width, int height, int transparency) {
    if (getColorModel().getTransparency() == transparency) {
      return createCompatibleImage(width, height);
    }

    ColorModel cm = getColorModel(transparency);
    if (cm == null) {
      throw new IllegalArgumentException("Unknown transparency: " + transparency);
    }
    WritableRaster wr = cm.createCompatibleWritableRaster(width, height);
    return new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
  }
Ejemplo n.º 10
0
  public Raster getRaster(int x, int y, int w, int h) {
    WritableRaster wr = cmodel.createCompatibleWritableRaster(w, h);

    int[] c = new int[3];
    double md1, md2, d1, d2, px, py;
    double a1, a2, b1, b2, c1, c2, denom;

    md1 = Point2D.distance((point[0].x), (point[0].y), (point[1].x), (point[1].y));
    md2 = Point2D.distance((point[0].x), (point[0].y), (point[2].x), (point[2].y));

    a1 = (point[1].y) - (point[0].y);
    b1 = (point[0].x) - (point[1].x);
    c1 = (point[1].x) * (point[0].y) - (point[0].x) * (point[1].y);

    a2 = (point[2].y) - (point[0].y);
    b2 = (point[0].x) - (point[2].x);

    denom = a1 * b2 - a2 * b1;
    if (!(denom != 0)) throw new Error("Assertion failed: " + "denom != 0");

    for (int i = 0; i < w; ++i) {
      for (int j = 0; j < h; ++j) {

        px = x + i;
        py = y + j;

        c2 = -(py * b2 + px * a2);
        double ix = (b1 * c2 - b2 * c1) / denom;
        double iy = (a2 * c1 - a1 * c2) / denom;

        d1 = Point2D.distance((point[0].x), (point[0].y), ix, iy);
        d2 = Point2D.distance(px, py, ix, iy);

        int w1, w2, w3;
        w2 = (int) Math.round((256.0 * d1) / md1);
        w3 = (int) Math.round((256.0 * d2) / md2);
        w1 = 256 - w2 - w3;

        c[0] =
            ((color[0].getRed() * w1) + (color[1].getRed() * w2) + (color[2].getRed() * w3)) / 256;
        c[1] =
            ((color[0].getGreen() * w1) + (color[1].getGreen() * w2) + (color[2].getGreen() * w3))
                / 256;
        c[2] =
            ((color[0].getBlue() * w1) + (color[1].getBlue() * w2) + (color[2].getBlue() * w3))
                / 256;

        wr.setPixel(i, j, c);
      }
    }
    return wr;
  }
 /**
  * Took this cacheRaster code from GradientPaint. It appears to recycle rasters for use by any
  * other instance, as long as they are sufficiently large.
  */
 protected static final synchronized WritableRaster getCachedRaster(ColorModel cm, int w, int h) {
   if (cm == cachedModel) {
     if (cached != null) {
       WritableRaster ras = (WritableRaster) cached.get();
       if (ras != null && ras.getWidth() >= w && ras.getHeight() >= h) {
         cached = null;
         return ras;
       }
     }
   }
   // Don't create rediculously small rasters...
   if (w < 32) w = 32;
   if (h < 32) h = 32;
   return cm.createCompatibleWritableRaster(w, h);
 }
 /*     */ private static synchronized Raster getCachedRaster(
     ColorModel paramColorModel, int paramInt1, int paramInt2)
       /*     */ {
   /* 657 */ if ((paramColorModel == cachedModel) && /* 658 */ (cached != null)) {
     /* 659 */ Raster localRaster = (Raster) cached.get();
     /* 660 */ if ((localRaster != null)
         && (localRaster.getWidth() >= paramInt1)
         && (localRaster.getHeight() >= paramInt2))
     /*     */ {
       /* 664 */ cached = null;
       /* 665 */ return localRaster;
       /*     */ }
     /*     */ }
   /*     */
   /* 669 */ return paramColorModel.createCompatibleWritableRaster(paramInt1, paramInt2);
   /*     */ }
Ejemplo n.º 13
0
  @Override
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();

    if (dst == null) {
      if (addMargins) {
        ColorModel cm = src.getColorModel();
        dst =
            new BufferedImage(
                cm,
                cm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()),
                cm.isAlphaPremultiplied(),
                null);
      } else dst = createCompatibleDestImage(src, null);
    }

    // Make a black mask from the image's alpha channel
    float[][] extractAlpha = {
      {0, 0, 0, 0},
      {0, 0, 0, 0},
      {0, 0, 0, 0},
      {0, 0, 0, opacity}
    };
    BufferedImage shadow = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    new BandCombineOp(extractAlpha, null).filter(src.getRaster(), shadow.getRaster());
    shadow = new GaussianFilter(radius).filter(shadow, null);

    Graphics2D g = dst.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
    if (addMargins) {
      int radius2 = radius / 2;
      int topShadow = Math.max(0, radius - yOffset);
      int leftShadow = Math.max(0, radius - xOffset);
      g.translate(topShadow, leftShadow);
    }
    g.drawRenderedImage(shadow, AffineTransform.getTranslateInstance(xOffset, yOffset));
    if (!shadowOnly) {
      g.setComposite(AlphaComposite.SrcOver);
      g.drawRenderedImage(src, null);
    }
    g.dispose();

    return dst;
  }
Ejemplo n.º 14
0
 public BufferedImage resize(BufferedImage src, double ratio) {
   int iw = src.getWidth();
   int ih = src.getHeight();
   int width = (int) (iw * ratio);
   int height = (int) (ih * ratio);
   ColorModel dstCM = src.getColorModel();
   BufferedImage dst =
       new BufferedImage(
           dstCM,
           dstCM.createCompatibleWritableRaster(width, height),
           dstCM.isAlphaPremultiplied(),
           null);
   Image scaleImage = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);
   Graphics2D g = dst.createGraphics();
   g.drawImage(scaleImage, 0, 0, width, height, null);
   g.dispose();
   return dst;
 }
Ejemplo n.º 15
0
 /**
  * Converts a rendered image to a {@code BufferedImage}. This utility method has come from a forum
  * post by Jim Moore at:
  *
  * <p><a href="http://www.jguru.com/faq/view.jsp?EID=114602">
  * http://www.jguru.com/faq/view.jsp?EID=114602</a>
  *
  * @param img the rendered image.
  * @return A buffered image.
  */
 private static BufferedImage convertRenderedImage(RenderedImage img) {
   if (img instanceof BufferedImage) {
     return (BufferedImage) img;
   }
   ColorModel cm = img.getColorModel();
   int width = img.getWidth();
   int height = img.getHeight();
   WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
   boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
   Hashtable properties = new Hashtable();
   String[] keys = img.getPropertyNames();
   if (keys != null) {
     for (int i = 0; i < keys.length; i++) {
       properties.put(keys[i], img.getProperty(keys[i]));
     }
   }
   BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
   img.copyData(raster);
   return result;
 }
 private static BufferedImage convertToAWT(ImageData data) {
   ColorModel colorModel = null;
   PaletteData palette = data.palette;
   colorModel = ColorModel.getRGBdefault();
   BufferedImage bufferedImage =
       new BufferedImage(
           colorModel,
           colorModel.createCompatibleWritableRaster(data.width, data.height),
           false,
           null);
   for (int y = 0; y < data.height; y++) {
     for (int x = 0; x < data.width; x++) {
       int pixel = data.getPixel(x, y);
       RGB rgb = palette.getRGB(pixel);
       byte alpha = (byte) data.getAlpha(x, y);
       bufferedImage.setRGB(x, y, alpha << 24 | rgb.red << 16 | rgb.green << 8 | rgb.blue);
     }
   }
   return bufferedImage;
 }
Ejemplo n.º 17
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int w = src.getWidth();
    int h = src.getHeight();

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(width, height),
              dstCM.isAlphaPremultiplied(),
              null);
    }

    Graphics2D g = dst.createGraphics();
    g.drawRenderedImage(src, AffineTransform.getTranslateInstance(-x, -y));
    g.dispose();

    return dst;
  }
Ejemplo n.º 18
0
 public BufferedImage crop(BufferedImage src, int left, int top, int width, int height) {
   int iw = src.getWidth();
   int ih = src.getHeight();
   if (left + width > iw) {
     width = iw - left;
   }
   if (top + height > ih) {
     height = ih - top;
   }
   ColorModel dstCM = src.getColorModel();
   BufferedImage dst =
       new BufferedImage(
           dstCM,
           dstCM.createCompatibleWritableRaster(width, height),
           dstCM.isAlphaPremultiplied(),
           null);
   Graphics2D g = dst.createGraphics();
   g.drawRenderedImage(src, AffineTransform.getTranslateInstance(-left, -top));
   g.dispose();
   return dst;
 }
Ejemplo n.º 19
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int w = src.getWidth();
    int h = src.getHeight();

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(w, h),
              dstCM.isAlphaPremultiplied(),
              null);
    }

    // Image scaleImage =
    src.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING);
    Graphics2D g = dst.createGraphics();
    g.drawImage(src, 0, 0, width, height, null);
    g.dispose();

    return dst;
  }
Ejemplo n.º 20
0
 /** @see Graphics2D#drawRenderedImage(RenderedImage, AffineTransform) */
 public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
   BufferedImage image = null;
   if (img instanceof BufferedImage) {
     image = (BufferedImage) img;
   } else {
     ColorModel cm = img.getColorModel();
     int width = img.getWidth();
     int height = img.getHeight();
     WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
     boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
     Hashtable properties = new Hashtable();
     String[] keys = img.getPropertyNames();
     if (keys != null) {
       for (int i = 0; i < keys.length; i++) {
         properties.put(keys[i], img.getProperty(keys[i]));
       }
     }
     BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
     img.copyData(raster);
     image = result;
   }
   drawImage(image, xform, null);
 }
Ejemplo n.º 21
0
  public static void main(String args[]) {
    try {
      ICC_Profile inProfile =
          ICC_Profile.getInstance("/System/Library/ColorSync/Profiles/AdobeRGB1998.icc");
      ICC_Profile outProfile =
          ICC_Profile.getInstance("/Library/ColorSync/Profiles/CIE 1931 D50 Gamma 1.icm");

      Profile cmsOutProfile = new Profile(outProfile);
      Profile cmsInProfile = new Profile(inProfile);

      BufferedImage inputImage = ImageIO.read(new File("/Stuff/Reference/small-q60-adobergb.TIF"));
      ShortInterleavedRaster inputRaster = (ShortInterleavedRaster) inputImage.getTile(0, 0);

      ColorSpace outCS = new ICC_ColorSpace(outProfile);
      ColorModel outCM =
          new ComponentColorModel(outCS, false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
      ShortInterleavedRaster outputRaster =
          (ShortInterleavedRaster)
              outCM.createCompatibleWritableRaster(inputImage.getWidth(), inputImage.getHeight());
      BufferedImage outputImage = new BufferedImage(outCM, outputRaster, false, null);

      Transform cmsTransform =
          new Transform(
              cmsInProfile, TYPE_RGB_16, cmsOutProfile, TYPE_RGB_16, INTENT_PERCEPTUAL, 0);

      cmsTransform.doTransform(inputRaster, outputRaster);

      ImageIO.write(outputImage, "TIF", new File("/Stuff/small-q60-CIED65.TIF"));

      cmsTransform.dispose();
      cmsOutProfile.dispose();
      cmsInProfile.dispose();
      // System.out.println("Profile: " + hProfile + ", " + );
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 22
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();

    int[] inPixels = getRGB(src, 0, 0, width, height, null);

    int x = 0, y = 0;
    int w = width;
    int h = height;

    int newX = 0;
    int newY = 0;
    int newW = w;
    int newH = h;
    switch (operation) {
      case FLIP_H:
        newX = width - (x + w);
        break;
      case FLIP_V:
        newY = height - (y + h);
        break;
      case FLIP_HV:
        newW = h;
        newH = w;
        newX = y;
        newY = x;
        break;
      case FLIP_90CW:
        newW = h;
        newH = w;
        newX = height - (y + h);
        newY = x;
        break;
      case FLIP_90CCW:
        newW = h;
        newH = w;
        newX = y;
        newY = width - (x + w);
        break;
      case FLIP_180:
        newX = width - (x + w);
        newY = height - (y + h);
        break;
    }

    int[] newPixels = new int[newW * newH];

    for (int row = 0; row < h; row++) {
      for (int col = 0; col < w; col++) {
        int index = row * width + col;
        int newRow = row;
        int newCol = col;
        switch (operation) {
          case FLIP_H:
            newCol = w - col - 1;
            break;
          case FLIP_V:
            newRow = h - row - 1;
            break;
          case FLIP_HV:
            newRow = col;
            newCol = row;
            break;
          case FLIP_90CW:
            newRow = col;
            newCol = h - row - 1;
            ;
            break;
          case FLIP_90CCW:
            newRow = w - col - 1;
            newCol = row;
            break;
          case FLIP_180:
            newRow = h - row - 1;
            newCol = w - col - 1;
            break;
        }
        int newIndex = newRow * newW + newCol;
        newPixels[newIndex] = inPixels[index];
      }
    }

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(newW, newH),
              dstCM.isAlphaPremultiplied(),
              null);
    }
    WritableRaster dstRaster = dst.getRaster();
    setRGB(dst, 0, 0, newW, newH, newPixels);

    return dst;
  }
Ejemplo n.º 23
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();

    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);

    if (dst == null) {
      ColorModel dstCM = src.getColorModel();
      dst =
          new BufferedImage(
              dstCM,
              dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height),
              dstCM.isAlphaPremultiplied(),
              null);
    }
    WritableRaster dstRaster = dst.getRaster();

    int[] inPixels = getRGB(src, 0, 0, width, height, null);

    if (interpolation == NEAREST_NEIGHBOUR)
      return filterPixelsNN(dst, width, height, inPixels, transformedSpace);

    int srcWidth = width;
    int srcHeight = height;
    int srcWidth1 = width - 1;
    int srcHeight1 = height - 1;
    int outWidth = transformedSpace.width;
    int outHeight = transformedSpace.height;
    int outX, outY;
    int index = 0;
    int[] outPixels = new int[outWidth];

    outX = transformedSpace.x;
    outY = transformedSpace.y;
    float[] out = new float[2];

    for (int y = 0; y < outHeight; y++) {
      for (int x = 0; x < outWidth; x++) {
        transformInverse(outX + x, outY + y, out);
        int srcX = (int) Math.floor(out[0]);
        int srcY = (int) Math.floor(out[1]);
        float xWeight = out[0] - srcX;
        float yWeight = out[1] - srcY;
        int nw, ne, sw, se;

        if (srcX >= 0 && srcX < srcWidth1 && srcY >= 0 && srcY < srcHeight1) {
          // Easy case, all corners are in the image
          int i = srcWidth * srcY + srcX;
          nw = inPixels[i];
          ne = inPixels[i + 1];
          sw = inPixels[i + srcWidth];
          se = inPixels[i + srcWidth + 1];
        } else {
          // Some of the corners are off the image
          nw = getPixel(inPixels, srcX, srcY, srcWidth, srcHeight);
          ne = getPixel(inPixels, srcX + 1, srcY, srcWidth, srcHeight);
          sw = getPixel(inPixels, srcX, srcY + 1, srcWidth, srcHeight);
          se = getPixel(inPixels, srcX + 1, srcY + 1, srcWidth, srcHeight);
        }
        outPixels[x] = ImageMath.bilinearInterpolate(xWeight, yWeight, nw, ne, sw, se);
      }
      setRGB(dst, 0, y, transformedSpace.width, 1, outPixels);
    }
    return dst;
  }
Ejemplo n.º 24
0
 /**
  * Creates a new managed image of the given width and height that is associated with the target
  * Component.
  */
 public Image createAcceleratedImage(Component target, int width, int height) {
   ColorModel model = getColorModel(Transparency.OPAQUE);
   WritableRaster wr = model.createCompatibleWritableRaster(width, height);
   return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied());
 }
Ejemplo n.º 25
0
 /**
  * Returns a BufferedImage with raster and color model compatible with this graphics
  * configuration. This method has nothing to do with memory-mapping a device. This BufferedImage
  * has a raster and color model that is closest to this native device configuration and thus can
  * be optimally blitted to this device.
  */
 public BufferedImage createCompatibleImage(int width, int height) {
   ColorModel model = getColorModel();
   WritableRaster raster = model.createCompatibleWritableRaster(width, height);
   return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null);
 }
Ejemplo n.º 26
0
  public WritableRaster copyData(WritableRaster wr) {
    // Get my source.
    CachableRed src = (CachableRed) getSources().get(0);

    Rectangle r = wr.getBounds();
    r.x -= xinset;
    r.y -= yinset;
    r.width += 2 * xinset;
    r.height += 2 * yinset;

    // System.out.println("Gaussian GenR: " + wr);
    // System.out.println("SrcReq: " + r);

    ColorModel srcCM = src.getColorModel();

    WritableRaster tmpR1 = null, tmpR2 = null;

    tmpR1 = srcCM.createCompatibleWritableRaster(r.width, r.height);
    {
      WritableRaster fill;
      fill = tmpR1.createWritableTranslatedChild(r.x, r.y);
      src.copyData(fill);
    }
    if (srcCM.hasAlpha() && !srcCM.isAlphaPremultiplied())
      GraphicsUtil.coerceData(tmpR1, srcCM, true);

    // For the blur box approx we can use dest as our intermediate
    // otherwise we let it default to null which means we create a new
    // one...

    // this lets the Vertical conv know how much is junk, so it
    // doesn't bother to convolve the top and bottom edges
    int skipX;
    // long t1 = System.currentTimeMillis();
    if (xinset == 0) {
      skipX = 0;
    } else if (convOp[0] != null) {
      tmpR2 = getColorModel().createCompatibleWritableRaster(r.width, r.height);
      tmpR2 = convOp[0].filter(tmpR1, tmpR2);
      skipX = convOp[0].getKernel().getXOrigin();

      // Swap them...
      WritableRaster tmp = tmpR1;
      tmpR1 = tmpR2;
      tmpR2 = tmp;
    } else {
      if ((dX & 0x01) == 0) {
        tmpR1 = boxFilterH(tmpR1, tmpR1, 0, 0, dX, dX / 2);
        tmpR1 = boxFilterH(tmpR1, tmpR1, dX / 2, 0, dX, dX / 2 - 1);
        tmpR1 = boxFilterH(tmpR1, tmpR1, dX - 1, 0, dX + 1, dX / 2);
        skipX = dX - 1 + dX / 2;
      } else {
        tmpR1 = boxFilterH(tmpR1, tmpR1, 0, 0, dX, dX / 2);
        tmpR1 = boxFilterH(tmpR1, tmpR1, dX / 2, 0, dX, dX / 2);
        tmpR1 = boxFilterH(tmpR1, tmpR1, dX - 2, 0, dX, dX / 2);
        skipX = dX - 2 + dX / 2;
      }
    }

    if (yinset == 0) {
      tmpR2 = tmpR1;
    } else if (convOp[1] != null) {
      if (tmpR2 == null) {
        tmpR2 = getColorModel().createCompatibleWritableRaster(r.width, r.height);
      }
      tmpR2 = convOp[1].filter(tmpR1, tmpR2);
    } else {
      if ((dY & 0x01) == 0) {
        tmpR1 = boxFilterV(tmpR1, tmpR1, skipX, 0, dY, dY / 2);
        tmpR1 = boxFilterV(tmpR1, tmpR1, skipX, dY / 2, dY, dY / 2 - 1);
        tmpR1 = boxFilterV(tmpR1, tmpR1, skipX, dY - 1, dY + 1, dY / 2);
      } else {
        tmpR1 = boxFilterV(tmpR1, tmpR1, skipX, 0, dY, dY / 2);
        tmpR1 = boxFilterV(tmpR1, tmpR1, skipX, dY / 2, dY, dY / 2);
        tmpR1 = boxFilterV(tmpR1, tmpR1, skipX, dY - 2, dY, dY / 2);
      }
      tmpR2 = tmpR1;
    }
    // long t2 = System.currentTimeMillis();
    // System.out.println("Time: " + (t2-t1) +
    //                       (((convOp[0] != null) || (convOp[1] != null))?
    //                        " ConvOp":""));
    // System.out.println("Rasters  WR :" + wr.getBounds());
    // System.out.println("         tmp:" + tmpR2.getBounds());
    // System.out.println("      bounds:" + getBounds());
    // System.out.println("       skipX:" + skipX +
    //                    " dx:" + dX + " Dy: " + dY);
    tmpR2 = tmpR2.createWritableTranslatedChild(r.x, r.y);
    GraphicsUtil.copyData(tmpR2, wr);

    return wr;
  }
Ejemplo n.º 27
0
 public z_WritableRaster createCompatibleWritableRaster(int width, int height) {
   z_WritableRaster z = new z_WritableRaster();
   z.raster = color.createCompatibleWritableRaster(width, height);
   return z;
 }