Java 类javafx.scene.image.PixelReader 实例源码

项目:voogasalad-ltub    文件:ImageTransformation.java   
@Override
public Set<Point2D> getMask(Image image, Color color) {
    PixelReader pixelReader = image.getPixelReader();
    Set<Point2D> mask = new HashSet<>();
    int pixel;
    boolean isTransparent, isBackgroundColor;
    for(int i =0; i < image.getWidth(); i++){
        for(int j = 0; j < image.getHeight(); j++){
            pixel = pixelReader.getArgb(i, j);
            //check the transparency of the pixel at (i,j)
            isTransparent = (pixel >> 24) == 0x00;              
            Color backgroundColor = pixelReader.getColor(i, j);
            isBackgroundColor = (color.equals(backgroundColor));
            if(!isTransparent && !isBackgroundColor){
                Point2D p = new Point2D(i,j);
                mask.add(p);
            }
        }
    }
    return mask;
}
项目:worldheatmap    文件:SimpleHeatMap.java   
private void updateHeatMap() {
    monochromeCanvas.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
    heatMap = new WritableImage(monochromeImage.widthProperty().intValue(), monochromeImage.heightProperty().intValue());
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    Color colorFromMonoChromeImage;
    double brightness;
    Color mappedColor;
    for (int y = 0 ; y < monochromeImage.getHeight() ; y++) {
        for (int x = 0 ; x < monochromeImage.getWidth(); x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            //brightness = computeLuminance(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
            //brightness = computeBrightness(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
            brightness = computeBrightnessFast(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
            mappedColor = getColorAt(mappingGradient, brightness);
            if (fadeColors) {
                //pixelWriter.setColor(x, y, Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness));
                pixelWriter.setColor(x, y, Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), colorFromMonoChromeImage.getOpacity()));
            } else {
                pixelWriter.setColor(x, y, mappedColor);
            }
        }
    }
    heatMapView.setImage(heatMap);
}
项目:worldheatmap    文件:HeatMap.java   
/**
 * Recreates the heatmap based on the current monochrome map.
 * Using this approach makes it easy to change the used color
 * mapping.
 */
private void updateHeatMap() {
    monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
    heatMap = new WritableImage(monochromeImage.widthProperty().intValue(), monochromeImage.heightProperty().intValue());
    Color       colorFromMonoChromeImage;
    double      brightness;
    Color       mappedColor;
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    int width  = (int) monochromeImage.getWidth();
    int height = (int) monochromeImage.getHeight();
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            brightness               = colorFromMonoChromeImage.getOpacity();
            mappedColor              = getColorAt(mappingGradient, brightness);
            pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
        }
    }
    setImage(heatMap);
}
项目:charts    文件:HeatMap.java   
/**
 * Recreates the heatmap based on the current monochrome map.
 * Using this approach makes it easy to change the used color
 * mapping.
 */
private void updateHeatMap() {
    monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);

    int width  = monochromeImage.widthProperty().intValue();
    int height = monochromeImage.heightProperty().intValue();
    heatMap    = new WritableImage(width, height);

    Color       colorFromMonoChromeImage;
    double      brightness;
    Color       mappedColor;
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            brightness               = colorFromMonoChromeImage.getOpacity();
            mappedColor              = Helper.getColorAt(mappingGradient, brightness);
            pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
        }
    }
    setImage(heatMap);
}
项目:minecraft-jfx-skin    文件:SkinMultipleCubes.java   
public Face(Image image, int startX, int startY, int width, int height, int interval, boolean reverseX, boolean reverseY,
        Supplier<Box> supplier, BiConsumer<Box, Point2D> consumer) {
    PixelReader reader = image.getPixelReader();
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
            int argb;
            if ((argb = reader.getArgb(startX + (reverseX ? width - x - 1 : x) * interval,
                    startY + (reverseY ? height - y - 1 : y) * interval)) != 0) {
                Box pixel = supplier.get();
                consumer.accept(pixel, new Point2D(x, y));
                pixel.setMaterial(createMaterial(Color.rgb(
                        (argb >> 16) & 0xFF, (argb >> 8) & 0xFF, (argb >> 0) & 0xFF)));
                getChildren().add(pixel);
            }
        }
}
项目:minecraft-jfx-skin    文件:SkinHelper.java   
public void copy(float srcX, float srcY, float toX, float toY, float width, float height, boolean reversalX, boolean reversalY) {
    PixelReader reader = srcImage.getPixelReader();
    PixelWriter writer = newImage.getPixelWriter();
    int srcScaleX = (int) srcImage.getWidth();
    int srcScaleY = (int) srcImage.getHeight();
    int newScaleX = (int) newImage.getWidth();
    int newScaleY = (int) newImage.getHeight();
    int srcWidth  = (int) (width * srcScaleX);
    int srcHeight = (int) (height * srcScaleY);

    for (int x = 0; x < srcWidth; x++)
        for (int y = 0; y < srcHeight; y++)
            writer.setArgb((int) (toX * newScaleX + x), (int) (toY * newScaleY + y),
                    reader.getArgb((int) (srcX * srcScaleX + (reversalX ? srcWidth - x - 1 : x)),
                            (int) (srcY * srcScaleY + (reversalY ? srcHeight - y - 1 : y))));
}
项目:NinePatch    文件:FxNinePatch.java   
@Override
public int[] getPixels(Image img, int x, int y, int w, int h)
{
    int[] pixels = new int[w * h];

    PixelReader reader = img.getPixelReader();

    PixelFormat.Type type =  reader.getPixelFormat().getType();

    WritablePixelFormat<IntBuffer> format = null;

    if(type == PixelFormat.Type.INT_ARGB_PRE)
    {
        format = PixelFormat.getIntArgbPreInstance();
    }
    else
    {
        format = PixelFormat.getIntArgbInstance();
    }

    reader.getPixels(x, y, w, h, format, pixels, 0, w);

    return pixels;
}
项目:Alchemy    文件:SkinHelper.java   
public void copy(float srcX, float srcY, float toX, float toY, float width, float height, boolean reversalX, boolean reversalY) {
    PixelReader reader = srcImage.getPixelReader();
    PixelWriter writer = newImage.getPixelWriter();
    int srcScaleX = (int) srcImage.getWidth();
    int srcScaleY = (int) srcImage.getHeight();
    int newScaleX = (int) newImage.getWidth();
    int newScaleY = (int) newImage.getHeight();
    int srcWidth  = (int) (width * srcScaleX);
    int srcHeight = (int) (height * srcScaleY);

    for (int x = 0; x < srcWidth; x++)
        for (int y = 0; y < srcHeight; y++)
            writer.setArgb((int) (toX * newScaleX + x), (int) (toY * newScaleY + y),
                    reader.getArgb((int) (srcX * srcScaleX + (reversalX ? srcWidth - x - 1 : x)),
                            (int) (srcY * srcScaleY + (reversalY ? srcHeight - y - 1 : y))));
}
项目:fictional-spoon    文件:Tiles.java   
public static Image get(String key, int tileX, int tileY) {
    if (!sheets.containsKey(key)) {
        throw new AssertionError("image does not exist");
    }

    // try to get image from cache
    if (tiles.get(key)[tileX][tileY] != null) {
        return tiles.get(key)[tileX][tileY];
    }

    // generate new image from sheet
    PixelReader reader = sheets.get(key).getPixelReader();
    WritableImage newImage = new WritableImage(reader, (WIDTH + MARGIN) * tileX, (HEIGHT + MARGIN) * tileY, WIDTH,
            HEIGHT);

    // put new image in cache
    tiles.get(key)[tileX][tileY] = newImage;

    return newImage;

}
项目:Krothium-Launcher    文件:TexturePreview.java   
/**
 * Renders a layer. Transparent colors and background color is ignored.
 * @param dstx Destination X
 * @param dsty Destination Y
 * @param w Width of the chunk
 * @param h Height of the chunk
 * @param pr The image pixel reader
 * @param pw The output pixel writer
 * @param srcx The X coordinate from the source skin
 * @param srcy The Y coordinate from the source skin
 */
private static void renderLayer(int dstx, int dsty, int w, int h, PixelReader pr, PixelWriter pw, int srcx, int srcy) {
    Color background = pr.getColor(0, 0);
    int x_origin = dstx;
    for (int y = srcy; y < srcy + h; y++){
        for (int x = srcx; x < srcx + w; x++) {
            Color c = pr.getColor(x, y);
            if (c.getOpacity() == 1 && !c.equals(background)) {
                pw.setColor(dstx, dsty, c);
            }
            dstx++;
        }
        dsty++;
        dstx = x_origin;
    }
}
项目:Krothium-Launcher    文件:Kernel.java   
/**
 * This method receives an image scales it
 * @param input Input image
 * @param scaleFactor Output scale factor
 * @return The resampled image
 */
public Image resampleImage(Image input, int scaleFactor) {
    int W = (int) input.getWidth();
    int H = (int) input.getHeight();
    WritableImage output = new WritableImage(
            W * scaleFactor,
            H * scaleFactor
    );
    PixelReader reader = input.getPixelReader();
    PixelWriter writer = output.getPixelWriter();
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            int argb = reader.getArgb(x, y);
            for (int dy = 0; dy < scaleFactor; dy++) {
                for (int dx = 0; dx < scaleFactor; dx++) {
                    writer.setArgb(x * scaleFactor + dx, y * scaleFactor + dy, argb);
                }
            }
        }
    }
    return output;
}
项目:blasteroids    文件:RenderUtils.java   
/**
   * Colorizes an image by the given amount
   * 
   * @param img Image
   * @param c Color
   * @param a Double amount
   * @return Image
   */
  public static Image colorizeImage(Image img, Color c, double a) {
    PixelReader reader = img.getPixelReader();
WritableImage write = new WritableImage((int) img.getWidth(), (int) img.getHeight());
PixelWriter writer = write.getPixelWriter();

for(int readY = 0; readY < img.getHeight(); readY++){
    for(int readX = 0; readX < img.getWidth(); readX++) {
        Color color = reader.getColor(readX, readY);
        if(color.getOpacity() == 0) continue;
        color = color.interpolate(c, a);
        writer.setColor(readX, readY, color);
    }
}

return (Image) write;
  }
项目:marlin-fx    文件:TestNonAARasterization.java   
public void update(Path2D p2d) {
    setPath(resultpath, p2d);
    Path p = makePath();
    WritableImage wimg = new WritableImage(TESTW, TESTH);
    renderPath(p2d, p, wimg);
    PixelReader pr = wimg.getPixelReader();
    GraphicsContext gc = resultcv.getGraphicsContext2D();
    gc.save();
    for (int y = 0; y < TESTH; y++) {
        for (int x = 0; x < TESTW; x++) {
            boolean inpath = p2d.contains(x + 0.5, y + 0.5);
            boolean nearpath = near(p2d, x + 0.5, y + 0.5, warn);
            int pixel = pr.getArgb(x, y);
            renderPixelStatus(gc, x, y, pixel, inpath, nearpath);
        }
    }
    gc.restore();
}
项目:reversegeocode    文件:BuildLayeredIndexSliced.java   
/**
 * Transfer pixels from the rendering buffer to the winner/alpha maps.
 *
 * @param img Rendering buffer
 * @param x1 Left
 * @param x2 Right
 * @param y1 Bottom
 * @param y2 Top
 * @param layer Output array
 * @param c Entity number
 */
public void transferPixels(WritableImage img, int x1, int x2, int y1, int y2, int[][] layer, int c) {
  assert (c > 0);
  PixelReader reader = img.getPixelReader();
  for(int y = y1, py = 0; y < y2; y++, py++) {
    final int[] rowy = layer[y];
    for(int x = x1, px = 0; x < x2; x++, px++) {
      int col = reader.getArgb(px, py);
      int alpha = (col & 0xFF);
      // Always ignore cover less than 10%
      if(alpha < 0x19) {
        continue;
      }
      // Clip value range to positive bytes,
      // alpha = alpha > 0x7F ? 0x7F : alpha;
      int oldalpha = rowy[x] >>> 24;
      if(alpha == 0xFF || alpha >= oldalpha) {
        rowy[x] = (alpha << 24) | c;
      }
    }
  }
}
项目:reversegeocode    文件:BuildLayeredIndex.java   
/**
 * Transfer pixels from the rendering buffer to the winner/alpha maps.
 *
 * @param img
 *            Rendering buffer
 * @param x1
 *            Left
 * @param x2
 *            Right
 * @param y1
 *            Bottom
 * @param y2
 *            Top
 * @param winner
 *            Output array
 * @param c
 *            Entity number
 */
public void transferPixels(WritableImage img, int x1, int x2, int y1,
        int y2, int[][] winner, int c) {
    PixelReader reader = img.getPixelReader();
    for (int y = y1, py = 0; y < y2; y++, py++) {
        for (int x = x1, px = 0; x < x2; x++, px++) {
            int col = reader.getArgb(px, py);
            int alpha = (col & 0xFF);
            // Always ignore cover less than 10%
            if (alpha < 0x19) {
                continue;
            }
            // Clip value range to positive bytes,
            alpha = alpha > 0x7F ? 0x7F : alpha;
            byte oldalpha = (byte) (winner[y][x] >>> 24);
            if (alpha == 0x7F || (alpha > 0 && alpha >= oldalpha)) {
                winner[y][x] = (alpha << 24) | c;
            }
        }
    }
}
项目:FXTutorials    文件:BasicEncoder.java   
@Override
public Image encode(Image image, String message) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();

    WritableImage copy = new WritableImage(image.getPixelReader(), width, height);
    PixelWriter writer = copy.getPixelWriter();
    PixelReader reader = image.getPixelReader();

    boolean[] bits = encode(message);

    IntStream.range(0, bits.length)
            .mapToObj(i -> new Pair<>(i, reader.getArgb(i % width, i / width)))
            .map(pair -> new Pair<>(pair.getKey(), bits[pair.getKey()] ? pair.getValue() | 1 : pair.getValue() &~ 1))
            .forEach(pair -> {
                int x = pair.getKey() % width;
                int y = pair.getKey() / width;

                writer.setArgb(x, y, pair.getValue());
            });

    return copy;
}
项目:FXTutorials    文件:DisintegrationApp.java   
private void disintegrate(Image image) {
    PixelReader pixelReader = image.getPixelReader();

    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            Color color = pixelReader.getColor(x, y);

            if (!color.equals(Color.TRANSPARENT)) {
                Particle p = new Particle(x + 700, y + 50, color);
                particles.add(p);
            }
        }
    }

    fullSize = particles.size();
}
项目:JavaOne2015JavaFXPitfalls    文件:PixelWriterTest.java   
@Test
public void testsetARGB() throws RunnerException {
    Image src = new Image("file:/Users/amo/Pictures/April_Mai/DSCF5453.jpg");
    PixelReader reader = src.getPixelReader();

    int width = (int) src.getWidth();
    int height = (int) src.getHeight();

    long startTime = System.currentTimeMillis();
    testARGB(reader,width,height);


    long stopTime = System.currentTimeMillis();
    long elapsedTime = stopTime - startTime;
    System.out.println(elapsedTime + " ms-");
}
项目:JavaOne2015JavaFXPitfalls    文件:PixelWriterTest.java   
private void testARGB(PixelReader reader, int width, int height) {
    for (int i = 0; i < 10; i++) {
        WritableImage dest = new WritableImage(width, height);
        PixelWriter writer = dest.getPixelWriter();

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                // reading a pixel from src image,
                // then writing a pixel to dest image
                //Color color = reader.getColor(x, y);
                //writer.setColor(x, y, color);

                // this way is also OK
                int argb = reader.getArgb(x, y);
                writer.setArgb(x, y, argb);


            }
        }

    }
}
项目:hex4j    文件:TileMapImages.java   
/**
 * This method proceeds one tile set
 * 
 * @param tileset
 * @param image
 */
private void initTileSetImages(TileSet tileset, Image image) {
    PixelReader reader = image.getPixelReader();
    int imageWidth = tileset.getTileWidth();
    int imageHeight = tileset.getTileHeight();
    Integer id = tileset.getFirstGid();
    int offsetX = 0;
    int offsetY = 0;
    int column = 0;

    for (int i = 0; i < tileset.getTilecount(); i++) {
        Image dest = copyImage(reader, imageWidth, imageHeight, offsetX, offsetY);
        images.put(id + i, dest);

        // calculate next offset
        column++;
        if (column >= tileset.getTilesPerRow()) {
            column = 0;
            offsetX = 0;
            offsetY += imageHeight;
        } else {
            offsetX += imageWidth;
        }
    }
}
项目:Connected-Mind-Neural-Network    文件:Organism.java   
private int _checkEnvironment(Image image)
{
    PixelReader reader = image.getPixelReader();

    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    Color color;

    for(int x = 0; x < width; x++)
    {
        for(int y = 0; y < height; y++)
        {
            color = reader.getColor(x, y);

            if(color.getRed() == 0.0 && color.getGreen() == 0.0 && color.getGreen() == 0.0)
            {
                return 0;
            }
        }
    }

    return 1;
}
项目:jace    文件:Font.java   
private static void initalize() {
    initialized = true;
    font = new int[256][8];
    Thread fontLoader = new Thread(() -> {
        InputStream in = Font.class.getClassLoader().getResourceAsStream("jace/data/font.png");
        Image image = new Image(in);
        PixelReader reader = image.getPixelReader();
        for (int i = 0; i < 256; i++) {
            int x = (i >> 4) * 13 + 2;
            int y = (i & 15) * 13 + 4;
            for (int j = 0; j < 8; j++) {
                int row = 0;
                for (int k = 0; k < 7; k++) {
                    Color color = reader.getColor((7 - k) + x, j + y);
                    boolean on = color.getRed() != 0;
                    row = (row << 1) | (on ? 0 : 1);
                }
                font[i][j] = row;
            }
        }
    });
    fontLoader.start();
}
项目:FrameViewer-AnTracks    文件:TemplateTracker.java   
/**
    * Returns the sum of the red, green, and blue components of all the pixels
    * of an image within a region.
    *
    * If the region extends outside the bounds of the image, each pixel
    * outside the bounds of the image is considered to have a value of zero.
    *
    * @param image the image to sum. This must not be null.
    * @param region The region of the image to sum pixels from. This must not
    * be null.
    * @return The sum of components
    */
   private static long brightnessSum(Image image, Rectangle region) {
final PixelReader reader = image.getPixelReader();
long sum = 0;
for (int y = region.y; y < region.y + region.height + 1; y++) {
    for (int x = region.x; x < region.x + region.width + 1; x++) {
    if (x >= 0 && x < image.getWidth() && y >= 0 && y < image
        .getHeight()) {
        int argb = reader.getArgb(x, y);
        // Sum the red, green, and blue components to get a value
        // between 0 and 765
        long brightness = ((argb >> 16) & 0xFF) + ((argb >> 8) & 0xFF) + (argb & 0xFF);
        sum += brightness;
    }
    }
}
return sum;
   }
项目:FX-IIO    文件:FXBufferedImage.java   
private static SampleModel crateSampleModel(final Image image) {
    PixelReader pixelReader = image.getPixelReader();

    @SuppressWarnings("rawtypes")
    PixelFormat pixelFormat = pixelReader.getPixelFormat();

    switch (pixelFormat.getType()) {
        case INT_ARGB_PRE:
        case INT_ARGB:
            return new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, (int) image.getWidth(), (int) image.getHeight(), new int[] {0xFF000000, 0xFF0000, 0xFF00, 0xFF});
        case BYTE_BGRA_PRE:
        case BYTE_BGRA:
        case BYTE_RGB:
            int sampleSize = getSampleSize(pixelFormat);
            return new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, (int) image.getWidth(), (int) image.getHeight(), sampleSize, sampleSize * (int) image.getWidth(), createOffsets(pixelFormat));
        case BYTE_INDEXED:
        default:
            throw new IllegalArgumentException("Unsupported pixel format: " + pixelFormat.getType());
    }
}
项目:tokentool    文件:ImageUtil.java   
public static Image resizeCanvas(Image imageSource, int newWidth, int newHeight, int offsetX, int offsetY) {
    int sourceWidth = (int) imageSource.getWidth();
    int sourceHeight = (int) imageSource.getHeight();

    // No work needed here...
    if (sourceWidth == newWidth && sourceHeight == newHeight)
        return imageSource;

    WritableImage outputImage = new WritableImage(newWidth, newHeight);
    PixelReader pixelReader = imageSource.getPixelReader();
    PixelWriter pixelWriter = outputImage.getPixelWriter();
    WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();

    int[] buffer = new int[sourceWidth * sourceHeight];
    pixelReader.getPixels(0, 0, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
    pixelWriter.setPixels(offsetX, offsetY, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);

    return outputImage;
}
项目:tokentool    文件:ImageUtil.java   
private static Image clipImageWithMask(Image imageSource, Image imageMask) {
    int imageWidth = (int) imageMask.getWidth();
    int imageHeight = (int) imageMask.getHeight();

    WritableImage outputImage = new WritableImage(imageWidth, imageHeight);
    PixelReader pixelReader_Mask = imageMask.getPixelReader();
    PixelReader pixelReader_Source = imageSource.getPixelReader();
    PixelWriter pixelWriter = outputImage.getPixelWriter();

    for (int readY = 0; readY < imageHeight; readY++) {
        for (int readX = 0; readX < imageWidth; readX++) {
            Color pixelColor = pixelReader_Mask.getColor(readX, readY);

            if (pixelColor.equals(Color.TRANSPARENT))
                pixelWriter.setColor(readX, readY, pixelReader_Source.getColor(readX, readY));
        }
    }

    return outputImage;
}
项目:tokentool    文件:ImageUtil.java   
private static Image processMagenta(Image inputImage, int colorThreshold, boolean overlayWanted) {
    int imageWidth = (int) inputImage.getWidth();
    int imageHeight = (int) inputImage.getHeight();

    WritableImage outputImage = new WritableImage(imageWidth, imageHeight);
    PixelReader pixelReader = inputImage.getPixelReader();
    PixelWriter pixelWriter = outputImage.getPixelWriter();

    for (int readY = 0; readY < imageHeight; readY++) {
        for (int readX = 0; readX < imageWidth; readX++) {
            Color pixelColor = pixelReader.getColor(readX, readY);

            if (isMagenta(pixelColor, COLOR_THRESHOLD) == overlayWanted)
                pixelWriter.setColor(readX, readY, Color.TRANSPARENT);
            else
                pixelWriter.setColor(readX, readY, pixelColor);

        }
    }

    return outputImage;
}
项目:Augendiagnose    文件:PupilAndIrisDetector.java   
/**
 * Collect the information of all circles around the center.
 *
 * @param maxRelevantRadius The maximal circle radius considered
 */
private void collectCircleInfo(final int maxRelevantRadius) {
    PixelReader pixelReader = mImage.getPixelReader();
    int maxPossibleRadius = (int) Math.min(
            Math.min(mImage.getWidth() - 1 - mXCenter, mXCenter),
            Math.min(mImage.getHeight() - 1 - mYCenter, mYCenter));
    int maxRadius = Math.min(maxRelevantRadius, maxPossibleRadius);
    // For iris refinement, ignore points on top and bottom
    long maxRadius2 = (maxRadius + 1) * (maxRadius + 1);
    for (int x = mXCenter - maxRadius; x <= mXCenter + maxRadius; x++) {
        for (int y = mYCenter - maxRadius; y <= mYCenter + maxRadius; y++) {
            long d2 = (x - mXCenter) * (x - mXCenter) + (y - mYCenter) * (y - mYCenter);
            if (d2 <= maxRadius2) {
                int d = (int) Math.round(Math.sqrt(d2));
                float brightness = getBrightness(pixelReader.getColor(x, y));
                addInfo(d, brightness);
            }
        }
    }

}
项目:jointry    文件:ImageUtil.java   
public static Image justResize(Canvas canvas) {
    SnapshotParameters params = new SnapshotParameters();
    params.setFill(Color.TRANSPARENT);

    PixelReader reader = canvas.snapshot(params, null).getPixelReader();

    double canvasWidth = canvas.getWidth();
    double canvasHeight = canvas.getHeight();

    int startX = getStartX(reader, canvasWidth, canvasHeight);
    int startY = getStartY(reader, canvasWidth, canvasHeight);
    int endX = getEndX(reader, canvasWidth, canvasHeight);
    int endY = getEndY(reader, canvasWidth, canvasHeight);

    //何も描かれていないキャンバス
    if (startX == 0 && startY == 0 && endX == 0 && endY == 0) {
        return null;
    }

    return new WritableImage(reader, startX, startY, endX - startX, endY - startY);
}
项目:lawless-legends    文件:Font.java   
private static void initalize() {
    initialized = true;
    font = new int[256][8];
    Thread fontLoader = new Thread(() -> {
        InputStream in = Font.class.getClassLoader().getResourceAsStream("jace/data/font.png");
        Image image = new Image(in);
        PixelReader reader = image.getPixelReader();
        for (int i = 0; i < 256; i++) {
            int x = (i >> 4) * 13 + 2;
            int y = (i & 15) * 13 + 4;
            for (int j = 0; j < 8; j++) {
                int row = 0;
                for (int k = 0; k < 7; k++) {
                    Color color = reader.getColor((7 - k) + x, j + y);
                    boolean on = color.getRed() != 0;
                    row = (row << 1) | (on ? 0 : 1);
                }
                font[i][j] = row;
            }
        }
    });
    fontLoader.start();
}
项目:Starbound-Mod-Manager    文件:FXHelper.java   
public static void setColor(final Node image, final double r, final double g, final double b) {

    Image src = ((ImageView) image).getImage();
    PixelReader reader = src.getPixelReader();

    int width = (int) src.getWidth();
    int height = (int) src.getHeight();

    WritableImage dest = new WritableImage(width, height);
    PixelWriter writer = dest.getPixelWriter();

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            Color c = new Color(r, g, b, reader.getColor(x, y).getOpacity());
            writer.setColor(x, y, c);
        }
    }

    ((ImageView) image).setImage(dest);

}
项目:minecraft-jfx-skin    文件:SkinHelper.java   
public void copy(int srcX, int srcY, int toX, int toY, int width, int height, boolean reversalX, boolean reversalY) {
    PixelReader reader = srcImage.getPixelReader();
    PixelWriter writer = newImage.getPixelWriter();
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++)
            writer.setArgb(toX + x, toY + y,
                    reader.getArgb(srcX + (reversalX ? width - x - 1 : x), srcY + (reversalY ? height - y - 1 : y)));
}
项目:minecraft-jfx-skin    文件:SkinHelper.java   
public static Image enlarge(Image srcSkin, int multiple) {
    WritableImage newSkin = new WritableImage((int) srcSkin.getWidth() * multiple, (int) srcSkin.getHeight() * multiple);
    PixelReader reader = srcSkin.getPixelReader();
    PixelWriter writer = newSkin.getPixelWriter();

    for (int x = 0, lenX = (int) srcSkin.getWidth(); x < lenX; x++)
        for (int y = 0, lenY = (int) srcSkin.getHeight(); y < lenY; y++)
            for (int mx = 0; mx < multiple; mx++)
                for (int my = 0; my < multiple; my++) {
                    int argb = reader.getArgb(x, y);
                    writer.setArgb(x * multiple + mx, y * multiple + my, argb);
                }

    return newSkin;
}
项目:openjfx-8u-dev-tests    文件:ReadImageTestBase.java   
@Test
public void readBlockColor(){
    ColorComponentProvider provider = getColorComponentProvider();

    Image testImage = getImage();
    PixelReader reader = testImage.getPixelReader();

    assertFalse("Open testing image", testImage.isError());

    int[] buf = new int[256 * 256];

    reader.getPixels(0, 0, 256, 256, PixelFormat.getIntArgbInstance(), buf, 0, 256);

    int samePixelsCounter = 0;

    for (int i = 1; i < testImage.getHeight() - 1; i++) {
        for (int j = 1; j < testImage.getWidth() - 1; j++) {

            if(provider.getComponent(buf[i * 256 + j]) ==
                    provider.getComponent(buf[(i + 1) * 256 + j]))
                samePixelsCounter++;

            testGradientImage(
                    provider.getComponent(buf[i * 256 + j]),
                    provider.getComponent(buf[i * 256 + (j - 1)]),
                    provider.getComponent(buf[(i + 1) * 256 + j]),
                    provider.getComponent(buf[i * 256 + (j - 1)]),
                    provider.getComponent(buf[i * 256 + (j + 1)]));
        }
    }

    assertTrue("More than half of the pixels the same color.",
            samePixelsCounter < 256 * 256 / 2);
}
项目:Push2Display    文件:USBDisplay.java   
/**
 * Send the image to the screen.
 *
 * @param image An image of size 960 x 160 pixel
 */
public void send (final Image image)
{
    if (this.handle == null)
        return;

    final ByteBuffer header = ByteBuffer.allocateDirect (HDR_SZ);
    final ByteBuffer buffer = ByteBuffer.allocateDirect (DATA_SZ);
    final IntBuffer transfered = IntBuffer.allocate (1);

    header.put (DISPLAY_HEADER);

    final PixelReader reader = image.getPixelReader ();
    for (int y = 0; y < HEIGHT; y++)
    {
        for (int x = 0; x < WIDTH; x++)
        {
            final Color color = reader.getColor (x, y);

            // 3b(low) green - 5b red / 5b blue - 3b (high) green, e.g. gggRRRRR BBBBBGGG

            final int red = (int) Math.round (color.getRed () * 31);
            final int green = (int) Math.round (color.getGreen () * 63);
            final int blue = (int) Math.round (color.getBlue () * 31);
            buffer.put ((byte) ((green & 0x07) << 5 | red & 0x1F));
            buffer.put ((byte) ((blue & 0x1F) << 3 | (green & 0x38) >> 3));
        }
        for (int x = 0; x < 128; x++)
            buffer.put ((byte) 0x00);
    }

    LibUsb.bulkTransfer (this.handle, (byte) 0x01, header, transfered, 1000L);
    LibUsb.bulkTransfer (this.handle, (byte) 0x01, buffer, transfered, 1000L);
}
项目:Alchemy    文件:SkinHelper.java   
public void copy(int srcX, int srcY, int toX, int toY, int width, int height, boolean reversalX, boolean reversalY) {
    PixelReader reader = srcImage.getPixelReader();
    PixelWriter writer = newImage.getPixelWriter();
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++)
            writer.setArgb(toX + x, toY + y,
                    reader.getArgb(srcX + (reversalX ? width - x - 1 : x), srcY + (reversalY ? height - y - 1 : y)));
}
项目:Alchemy    文件:SkinHelper.java   
public static Image enlarge(Image srcSkin, int multiple) {
    WritableImage newSkin = new WritableImage((int) srcSkin.getWidth() * multiple, (int) srcSkin.getHeight() * multiple);
    PixelReader reader = srcSkin.getPixelReader();
    PixelWriter writer = newSkin.getPixelWriter();

    for (int x = 0, lenX = (int) srcSkin.getWidth(); x < lenX; x++)
        for (int y = 0, lenY = (int) srcSkin.getHeight(); y < lenY; y++)
            for (int mx = 0; mx < multiple; mx++)
                for (int my = 0; my < multiple; my++) {
                    int argb = reader.getArgb(x, y);
                    writer.setArgb(x * multiple + mx, y * multiple + my, argb);
                }

    return newSkin;
}
项目:Krothium-Launcher    文件:TexturePreview.java   
/**
 * Generates the left preview of the skin
 * @param skin The skin image
 * @param cape The cape image
 * @return The generated preview image
 */
public static Image generateLeft(Image skin, Image cape) {
    double h = skin.getHeight();
    PixelReader pr = skin.getPixelReader();
    WritableImage wi = new WritableImage(8, 32);
    PixelWriter pw = wi.getPixelWriter();
    if (h == 64) { // New format
        //MAIN ZONES
        //Head
        pw.setPixels(0, 0, 8, 8, pr, 16, 8);
        //Left Arm
        pw.setPixels(2, 8, 4, 12, pr, 40, 52);
        //Left Leg
        pw.setPixels(2, 20, 4, 12, pr, 24, 52);

        //EXTRA ZONES
        //Head
        renderLayer(0, 0, 8, 8, pr, pw, 48, 8);
        //Left Arm
        renderLayer(2, 8, 4, 12, pr, pw, 56, 52);
        //Left Leg
        renderLayer(2, 20, 4, 12, pr, pw, 8, 52);
    } else if (h == 32) { //Legacy format
        //Head
        pw.setPixels(0, 0, 8, 8, pr, 16, 8);
        //Hat
        renderLayer(0, 0, 8, 8, pr, pw, 48, 8);
        //Left Arm
        renderLayerInverse(2, 8, 4, 12, pr, pw, 40, 20);
        //Left Leg
        renderLayerInverse(2, 20, 4, 12, pr, pw, 0, 20);
    }

    if (cape != null) {
        PixelReader pr2 = cape.getPixelReader();
        pw.setPixels(6, 8, 1, 16, pr2, 0, 1);
    }

    return wi;
}
项目:Krothium-Launcher    文件:TexturePreview.java   
/**
 * Generates the right preview of the skin
 * @param skin The skin image
 * @param cape The cape image
 * @return The generated preview image
 */
public static Image generateRight(Image skin, Image cape) {
    double h = skin.getHeight();
    PixelReader pr = skin.getPixelReader();
    WritableImage wi = new WritableImage(8, 32);
    PixelWriter pw = wi.getPixelWriter();
    if (h == 64) { // New format
        //MAIN ZONES
        //Head
        pw.setPixels(0, 0, 8, 8, pr, 0, 8);
        //Right Arm
        pw.setPixels(2, 8, 4, 12, pr, 40, 20);
        //Right Leg
        pw.setPixels(2, 20, 4, 12, pr, 0, 20);

        //EXTRA ZONES
        //Head
        renderLayer(0, 0, 8, 8, pr, pw, 32, 8);
        //Right Arm
        renderLayer(2, 8, 4, 12, pr, pw, 40, 36);
        //Right Leg
        renderLayer(2, 20, 4, 12, pr, pw, 0, 36);
    } else if (h == 32) { //Legacy format
        //Head
        pw.setPixels(0, 0, 8, 8, pr, 0, 8);
        //Hat
        renderLayer(0, 0, 8, 8, pr, pw, 32, 8);
        //Right Arm
        pw.setPixels(2, 8, 4, 12, pr,40, 20);
        //Right Leg
        pw.setPixels(2, 20, 4, 12, pr, 0, 20);
    }

    if (cape != null) {
        PixelReader pr2 = cape.getPixelReader();
        pw.setPixels(1, 8, 1, 16, pr2, 11, 1);
    }

    return wi;
}
项目:Krothium-Launcher    文件:TexturePreview.java   
/**
 * Renders a layer inversed
 * @param dstx Destination X
 * @param dsty Destination Y
 * @param w Width of the chunk
 * @param h Height of the chunk
 * @param pr The image pixel reader
 * @param pw The output pixel writer
 * @param srcx The X coordinate from the source skin
 * @param srcy The Y coordinate from the source skin
 */
private static void renderLayerInverse(int dstx, int dsty, int w, int h, PixelReader pr, PixelWriter pw, int srcx, int srcy) {
    int x_origin = dstx;
    for (int y = srcy; y < srcy + h; y++){
        for (int x = srcx + w - 1; x >= srcx; x--) {
            Color c = pr.getColor(x, y);
            pw.setColor(dstx, dsty, c);
            dstx++;
        }
        dsty++;
        dstx = x_origin;
    }
}