Java Code Examples for javafx.scene.image.PixelWriter#setArgb()

The following examples show how to use javafx.scene.image.PixelWriter#setArgb() . 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: ColorMapDialog.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Update color bar in UI from current 'map' */
private void updateColorBar()
{
    // On Mac OS X it was OK to create an image sized 256 x 1:
    // 256 wide to easily set the 256 colors,
    // 1 pixel height which is then stretched via the BackgroundSize().
    // On Linux, the result was garbled unless the image height matched the
    // actual height, so it's now fixed to COLOR_BAR_HEIGHT
    final WritableImage colors = new WritableImage(256, COLOR_BAR_HEIGHT);
    final PixelWriter writer = colors.getPixelWriter();
    for (int x=0; x<256; ++x)
    {
        final int arfb = ColorMappingFunction.getRGB(map.getColor(x));
        for (int y=0; y<COLOR_BAR_HEIGHT; ++y)
            writer.setArgb(x, y, arfb);
    }
    // Stretch image to fill color_bar
    color_bar.setBackground(new Background(
            new BackgroundImage(colors, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
                                BackgroundPosition.DEFAULT,
                                new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true))));
}
 
Example 2
Source File: NinePatch.java    From oim-fx with MIT License 4 votes vote down vote up
/**
 * 生成指定宽高图片
 *
 * @param scaledWidth
 * @param scaledHeight
 * @return
 */
public Image generate(int scaledWidth, int scaledHeight) {
    WritableImage result = new WritableImage(scaledWidth, scaledHeight);
    PixelReader reader = origin.getPixelReader();
    PixelWriter writer = result.getPixelWriter();
    int originHCenterWidth = (int) origin.getWidth() - right - left;
    int originVCenterWidth = (int) origin.getHeight() - top - bottom;
    /* first row */
    writer.setPixels(0, 0, left, top, reader, 0, 0);
    for (int y = 0; y < top; y++) {
        for (int x = left; x < scaledWidth - right; x++) {
            writer.setArgb(x, y, reader.getArgb(left + (x - left) % originHCenterWidth, y));
        }
    }
    writer.setPixels(scaledWidth - right, 0, right, top, reader, (int) origin.getWidth() - right, 0);
    /* second row */
    for (int y = top; y < scaledHeight - bottom; y++) {
        for (int x = 0; x < left; x++) {
            writer.setArgb(x, y, reader.getArgb(x, top + (y - top) % originVCenterWidth));
        }
    }
    for (int y = top; y < scaledHeight - bottom; y++) {
        for (int x = left; x < scaledWidth - right; x++) {
            writer.setArgb(x, y,
                    reader.getArgb(left + (x - left) % originHCenterWidth, top + (y - top) % originVCenterWidth));
        }
    }
    for (int y = top; y < scaledHeight - bottom; y++) {
        for (int x = scaledWidth - right; x < scaledWidth; x++) {
            writer.setArgb(x, y,
                    reader.getArgb((int) origin.getWidth() + x - scaledWidth, top + (y - top) % originVCenterWidth));
        }
    }
    /* third row */
    writer.setPixels(0, scaledHeight - bottom, left, bottom, reader, 0, (int) origin.getHeight() - bottom);
    for (int y = scaledHeight - bottom; y < scaledHeight; y++) {
        for (int x = left; x < scaledWidth - right; x++) {
            writer.setArgb(x, y,
                    reader.getArgb(left + (x - left) % originHCenterWidth, (int) origin.getHeight() + y - scaledHeight));
        }
    }
    writer.setPixels(scaledWidth - right, scaledHeight - bottom, right, bottom, reader,
            (int) origin.getWidth() - right, (int) origin.getHeight() - bottom);
    return result;
}
 
Example 3
Source File: VideoNTSC.java    From jace with GNU General Public License v2.0 4 votes vote down vote up
private void renderScanline(WritableImage screen, int y) {
        int p = 0;
        if (rowStart != 0) {
//            getCurrentWriter().markDirty(y);
            p = rowStart * 28;
            if (rowStart < 0) {
                return;
            }
        }
        PixelWriter writer = screen.getPixelWriter();
        // Reset scanline position
        int byteCounter = 0;
        for (int s = rowStart; s < 20; s++) {
            int add = 0;
            int bits;
            if (hiresMode) {
                bits = scanline[s] << 2;
                if (s > 0) {
                    bits |= (scanline[s - 1] >> 26) & 3;
                }
            } else {
                bits = scanline[s] << 3;
                if (s > 0) {
                    bits |= (scanline[s - 1] >> 25) & 7;
                }
            }
            if (s < 19) {
                add = (scanline[s + 1] & 7);
            }
            boolean isBW = false;
            boolean mixed = enableVideo7 && dhgrMode && graphicsMode == rgbMode.MIX;
            for (int i = 0; i < 28; i++) {
                if (i % 7 == 0) {
                    isBW = monochomeMode || !colorActive[byteCounter] || (mixed && !hiresMode && !useColor[byteCounter]);
                    byteCounter++;
                }
                if (isBW) {
                    writer.setColor(p++, y, ((bits & 0x8) == 0) ? BLACK : WHITE);
                } else {
                    writer.setArgb(p++, y, activePalette[i % 4][bits & 0x07f]);
                }
                bits >>= 1;
                if (i == 20) {
                    bits |= add << (hiresMode ? 9 : 10);
                }
            }
//                    } else {
//                        for (int i = 0; i < 28; i++) {
//                            writer.setArgb(p++, y, activePalette[i % 4][bits & 0x07f]);
//                            bits >>= 1;
//                            if (i == 20) {
//                                bits |= add << (hiresMode ? 9 : 10);
//                            }
//                        }
//                    }
        }
        Arrays.fill(scanline, 0);
        rowStart = -1;
    }