com.juankysoriano.rainbow.core.graphics.RainbowImage Java Examples

The following examples show how to use com.juankysoriano.rainbow.core.graphics.RainbowImage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EdgeDetector.java    From rainbow with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<RVector> extractPoints(RainbowImage img) {
    List<RVector> vertices = new ArrayList<>();
    int col = 0, colSum = 0, W = img.width - 1, H = img.height - 1;

    // For any pixel in the image excepting borders
    for (int Y = 1; Y < H; Y += step) {
        for (int X = 1; X < W; X += step, colSum = 0) {
            // Convolute surrounding pixels with desired operator
            for (int y = -1; y <= 1; y++) {
                for (int x = -1; x <= 1; x++, col = img.get((X + x), (Y + y))) {
                    colSum += OPERATOR[op][x + 1][y + 1] * ((col >> 16 & 0xFF) + (col >> 8 & 0xFF) + (col & 0xFF));
                }
            }
            // And if the resulting sum is over the treshold add pixel
            // position to the list
            if (RainbowMath.abs(colSum) > treshold) {
                vertices.add(new RVector(X, Y));
            }
        }
    }
    return vertices;
}
 
Example #2
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadImage(Bitmap bitmap, RainbowImage.LoadPictureListener listener) {
    if (bitmap == null) {
        listener.onLoadFail();
    } else {
        RainbowImage image = new RainbowImage(bitmap);
        image.parent = graphics.parent;
        listener.onLoadSucceed(image);
    }
}
 
Example #3
Source File: FlowerDrawerTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThatPaintFlowerPerformsImagePaintOnRainbowDrawer() {
    givenThatHasImages();
    Branch branch = givenABranch();
    flowerDrawer.paintFlowerFor(branch);

    verify(rainbowDrawer).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat());
}
 
Example #4
Source File: FlowerDrawerTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThatPaintFlowerPerformsTranslationBeforePaintingImage() {
    givenThatHasImages();
    Branch branch = givenABranch();
    flowerDrawer.paintFlowerFor(branch);

    InOrder drawingOperation = inOrder(rainbowDrawer);

    drawingOperation.verify(rainbowDrawer).translate(anyFloat(), anyFloat());
    drawingOperation.verify(rainbowDrawer).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat());
}
 
Example #5
Source File: InkPerformerTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
private void disableRainbowDrawerInvocations() {
    Mockito.doNothing().when(rainbowDrawer).noStroke();
    Mockito.doNothing().when(rainbowDrawer).smooth();
    Mockito.doNothing().when(rainbowDrawer).tint(anyInt());
    Mockito.doNothing().when(rainbowDrawer).pushMatrix();
    Mockito.doNothing().when(rainbowDrawer).translate(anyFloat(), anyFloat());
    Mockito.doNothing().when(rainbowDrawer).rotate(anyFloat());
    Mockito.doNothing().when(rainbowDrawer).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat());
    Mockito.doNothing().when(rainbowDrawer).tint(anyInt());
    Mockito.doNothing().when(rainbowDrawer).stroke(anyInt(), anyFloat());
    Mockito.doNothing().when(rainbowDrawer).strokeWeight(anyFloat());
    Mockito.doNothing().when(rainbowDrawer).line(anyFloat(), anyFloat(), anyFloat(), anyFloat());

}
 
Example #6
Source File: GameOfLifeDrawer.java    From MaterialLife with GNU General Public License v2.0 5 votes vote down vote up
int getCellStateFrom(RainbowImage image, int cellX, int cellY) {
    int color = image.get(cellX * SCALE_FACTOR, cellY * SCALE_FACTOR);
    int red = (int) rainbowDrawer.red(color);
    int green = (int) rainbowDrawer.green(color);
    int blue = (int) rainbowDrawer.blue(color);
    int grey = (red + green + blue) / THREE;

    return grey < ALIVE_CELL_THRESHOLD ? GameOfLife.DEAD : GameOfLife.ALIVE;
}
 
Example #7
Source File: GameOfLife.java    From MaterialLife with GNU General Public License v2.0 5 votes vote down vote up
public void loadWorldFrom(RainbowImage image) {
    for (int i = 0; i < gameOfLifeAutomata.getWidth(); i++) {
        for (int j = 0; j < gameOfLifeAutomata.getHeight(); j++) {
            gameOfLifeAutomata.getCells()[i][j] = gameOfLifeDrawer.getCellStateFrom(image, i, j);
        }
    }
}
 
Example #8
Source File: LuminanceMap.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
static LuminanceMap newInstance(RainbowImage rainbowImage) {
    int width = rainbowImage.getWidth();
    int height = rainbowImage.getHeight();
    rainbowImage.loadPixels();
    int[] pixels = rainbowImage.pixels;
    boolean[] luminanceValues = new boolean[width * height];
    boolean[] visitedPixels = new boolean[width * height];
    return new LuminanceMap(pixels, width, height, luminanceValues, visitedPixels);
}
 
Example #9
Source File: RainbowBlobDetection.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onSketchSetup() {
    super.onSketchSetup();
    getRainbowDrawer().smooth();
    getRainbowDrawer().noFill();
    getRainbowDrawer().background(0, 0, 0);
    getRainbowDrawer().loadImage(
            R.drawable.winnie,
            (getWidth() / RESIZE_FACTOR),
            (getHeight() / RESIZE_FACTOR),
            Modes.LoadMode.LOAD_CENTER_CROP,
            new RainbowImage.LoadPictureListener() {

                @Override
                public void onLoadSucceed(RainbowImage image) {
                    rainbowImage = image;
                    mediaPlayer.start();
                    blobDetection = new BlobDetection(rainbowImage);
                    resetThreshold();
                    startNextBunchDetection();
                }

                @Override
                public void onLoadFail() {
                    //no-op
                }
            }
    );
}
 
Example #10
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(String path, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(path, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #11
Source File: BlobDetection.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BlobDetection(RainbowImage rainbowImage) {
    this(rainbowImage, DEFAULT_MAX_NUMBER_OF_BLOBS);
}
 
Example #12
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(String path, int width, int height, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(path, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #13
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(int resID, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(resID, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #14
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(int resID, int width, int height, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(resID, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #15
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(File file, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(file, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #16
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(Uri uri, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(uri, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #17
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadImage(Uri uri, int width, int height, Modes.LoadMode mode, RainbowImage.LoadPictureListener listener) {
    Bitmap bitmap = RainbowBitmapUtils.getBitmap(uri, width, height, mode);
    loadImage(bitmap, listener);
}
 
Example #18
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Copies area of one image into another PImage object.
 */
public void copy(RainbowImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) {
    graphics.copy(src, sx, sy, sw, sh, dx, dy, dw, dh);
}
 
Example #19
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Set alpha channel for an image using another image as the source.
 */
public void mask(RainbowImage alpha) {
    graphics.mask(alpha);
}
 
Example #20
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setOverlay(RainbowImage rainbowImage) {
    graphics.setOverlay(rainbowImage);
}
 
Example #21
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns a copy of this PImage. Equivalent to get(0, 0, width, height).
 */
public RainbowImage get() {
    return graphics.get();
}
 
Example #22
Source File: RainbowDrawer.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public RainbowImage createImage(int wide, int high, Modes.Image format) {
    RainbowImage image = new RainbowImage(wide, high, format);
    image.parent = graphics.parent;
    return image;
}
 
Example #23
Source File: FlowerDrawer.java    From Zen with GNU General Public License v2.0 4 votes vote down vote up
FlowerDrawer(Flower flower, List<RainbowImage> flowerImages, RainbowDrawer rainbowDrawer) {
    this.flower = flower;
    this.flowerImages = flowerImages;
    this.rainbowDrawer = rainbowDrawer;
}
 
Example #24
Source File: BlobDetection.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
private BlobDetection(RainbowImage rainbowImage, int maxNumberOfBlobs) {
    this.luminanceMap = LuminanceMap.newInstance(rainbowImage);
    this.maxNumberOfBlobs = maxNumberOfBlobs;
    scheduler = RainbowSchedulers.singleForRecursion("BlobDetection", RainbowSchedulers.Priority.NORMAL);
}
 
Example #25
Source File: RainbowMath.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static RainbowImage[] expand(final RainbowImage list[], final int newSize) {
    final RainbowImage temp[] = new RainbowImage[newSize];
    System.arraycopy(list, 0, temp, 0, Math.min(newSize, list.length));
    return temp;
}
 
Example #26
Source File: RainbowMath.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static RainbowImage[] expand(final RainbowImage list[]) {
    return RainbowMath.expand(list, list.length << 1);
}
 
Example #27
Source File: World.java    From MaterialLife with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onLoadSucceed(RainbowImage image) {
    gameOfLife.loadWorldFrom(image);
}
 
Example #28
Source File: FlowerDrawerTest.java    From Zen with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testThatPaintFlowerForBranchDoesNothingIfHasNoFlowersToPaint() {
    flowerDrawer.paintFlowerFor(givenABranch());

    verify(rainbowDrawer, never()).image(any(RainbowImage.class), anyFloat(), anyFloat(), anyFloat(), anyFloat());
}
 
Example #29
Source File: InkPerformer.java    From Zen with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onLoadSucceed(RainbowImage imageLoaded) {
    image = imageLoaded;
}
 
Example #30
Source File: FlowerDrawer.java    From Zen with GNU General Public License v2.0 4 votes vote down vote up
private RainbowImage getRandomFlower() {
    return flowerImages.get((int) RainbowMath.random(flowerImages.size()));
}