private void singleGradient(int[] pixels, int w, int h, float rowrel, float dx, float dy) { int off = 0; for (int y = 0; y < h; y++) { float colrel = rowrel; int j = w; int rgb; if (colrel <= 0.0) { rgb = colormap.getColor(0); do { pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; colrel += dx; } while (--j > 0 && colrel <= 0.0); } while (colrel < 1.0 && --j >= 0) { if (type == BILINEAR) rgb = colormap.getColor(map(ImageMath.triangle(colrel))); else rgb = colormap.getColor(map(colrel)); pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; colrel += dx; } if (j > 0) { if (type == BILINEAR) rgb = colormap.getColor(0.0f); else rgb = colormap.getColor(1.0f); do { pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; } while (--j > 0); } rowrel += dy; } }
private int displace(int rgb, float amount) { int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; r = PixelUtils.clamp(r + (int) (amount * (randomGenerator.nextFloat() - 0.5))); g = PixelUtils.clamp(g + (int) (amount * (randomGenerator.nextFloat() - 0.5))); b = PixelUtils.clamp(b + (int) (amount * (randomGenerator.nextFloat() - 0.5))); return 0xff000000 | (r << 16) | (g << 8) | b; }
/** Convolve with a 2D kernel */ public static void convolveHV( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int rows = kernel.getHeight(); int cols = kernel.getWidth(); int rows2 = rows / 2; int cols2 = cols / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float r = 0, g = 0, b = 0, a = 0; for (int row = -rows2; row <= rows2; row++) { int iy = y + row; int ioffset; if (0 <= iy && iy < height) ioffset = iy * width; else if (edgeAction == CLAMP_EDGES) ioffset = y * width; else if (edgeAction == WRAP_EDGES) ioffset = ((iy + height) % height) * width; else continue; int moffset = cols * (row + rows2) + cols2; for (int col = -cols2; col <= cols2; col++) { float f = matrix[moffset + col]; if (f != 0) { int ix = x + col; if (!(0 <= ix && ix < width)) { if (edgeAction == CLAMP_EDGES) ix = x; else if (edgeAction == WRAP_EDGES) ix = (x + width) % width; else continue; } int rgb = inPixels[ioffset + ix]; a += f * ((rgb >> 24) & 0xff); r += f * ((rgb >> 16) & 0xff); g += f * ((rgb >> 8) & 0xff); b += f * (rgb & 0xff); } } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5)) : 0xff; int ir = PixelUtils.clamp((int) (r + 0.5)); int ig = PixelUtils.clamp((int) (g + 0.5)); int ib = PixelUtils.clamp((int) (b + 0.5)); outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib; } } }
public static void convolveH( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int cols = kernel.getWidth(); int cols2 = cols / 2; for (int y = 0; y < height; y++) { int ioffset = y * width; for (int x = 0; x < width; x++) { float r = 0.0F; float g = 0.0F; float b = 0.0F; float a = 0.0F; int moffset = cols2; for (int col = -cols2; col <= cols2; col++) { float f = matrix[(moffset + col)]; if (f != 0.0F) { int ix = x + col; if (ix < 0) { if (edgeAction == CLAMP_EDGES) { ix = 0; } else if (edgeAction == WRAP_EDGES) { ix = (x + width) % width; } } else if (ix >= width) { if (edgeAction == CLAMP_EDGES) { ix = width - 1; } else if (edgeAction == WRAP_EDGES) { ix = (x + width) % width; } } int rgb = inPixels[(ioffset + ix)]; a += f * (rgb >> 24 & 0xFF); r += f * (rgb >> 16 & 0xFF); g += f * (rgb >> 8 & 0xFF); b += f * (rgb & 0xFF); } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5D)) : 255; int ir = PixelUtils.clamp((int) (r + 0.5D)); int ig = PixelUtils.clamp((int) (g + 0.5D)); int ib = PixelUtils.clamp((int) (b + 0.5D)); outPixels[(index++)] = (ia << 24 | ir << 16 | ig << 8 | ib); } } }
/** * Mutate the gradient. * * @param amount the amount in the range zero to one */ public void mutate(float amount) { for (int i = 0; i < numKnots; i++) { int rgb = yKnots[i]; int r = ((rgb >> 16) & 0xff); int g = ((rgb >> 8) & 0xff); int b = (rgb & 0xff); r = PixelUtils.clamp((int) (r + amount * 255 * (Math.random() - 0.5))); g = PixelUtils.clamp((int) (g + amount * 255 * (Math.random() - 0.5))); b = PixelUtils.clamp((int) (b + amount * 255 * (Math.random() - 0.5))); yKnots[i] = 0xff000000 | (r << 16) | (g << 8) | b; knotTypes[i] = RGB | SPLINE; } sortKnots(); rebuildGradient(); }
/** Convolve with a kernel consisting of one column */ public static void convolveV( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int rows = kernel.getHeight(); int rows2 = rows / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float r = 0, g = 0, b = 0, a = 0; for (int row = -rows2; row <= rows2; row++) { int iy = y + row; int ioffset; if (iy < 0) { if (edgeAction == CLAMP_EDGES) ioffset = 0; else if (edgeAction == WRAP_EDGES) ioffset = ((y + height) % height) * width; else ioffset = iy * width; } else if (iy >= height) { if (edgeAction == CLAMP_EDGES) ioffset = (height - 1) * width; else if (edgeAction == WRAP_EDGES) ioffset = ((y + height) % height) * width; else ioffset = iy * width; } else ioffset = iy * width; float f = matrix[row + rows2]; if (f != 0) { int rgb = inPixels[ioffset + x]; a += f * ((rgb >> 24) & 0xff); r += f * ((rgb >> 16) & 0xff); g += f * ((rgb >> 8) & 0xff); b += f * (rgb & 0xff); } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5)) : 0xff; int ir = PixelUtils.clamp((int) (r + 0.5)); int ig = PixelUtils.clamp((int) (g + 0.5)); int ib = PixelUtils.clamp((int) (b + 0.5)); outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib; } } }
public int getPixel(int x, int y, int[] inPixels, int width, int height) { float nx = m00 * x + m01 * y; float ny = m10 * x + m11 * y; nx /= scale; ny /= scale * stretch; nx += 1000; ny += 1000; // Reduce artifacts around 0,0 float f = turbulence == 1.0f ? evaluate(nx, ny) : turbulence2(nx, ny, turbulence); // Normalize to 0..1 // f = (f-min)/(max-min); f *= 2; f *= amount; int a = 0xff000000; int v; if (colormap != null) { v = colormap.getColor(f); if (useColor) { int srcx = ImageMath.clamp((int) ((results[0].x - 1000) * scale), 0, width - 1); int srcy = ImageMath.clamp((int) ((results[0].y - 1000) * scale), 0, height - 1); v = inPixels[srcy * width + srcx]; f = (results[1].distance - results[0].distance) / (results[1].distance + results[0].distance); f = ImageMath.smoothStep(coefficients[1], coefficients[0], f); v = ImageMath.mixColors(f, 0xff000000, v); } return v; } else { v = PixelUtils.clamp((int) (f * 255)); int r = v << 16; int g = v << 8; int b = v; return a | r | g | b; } }
protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) { int index = 0; int[] outPixels = new int[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int pixel = 0xffffffff; for (int dy = -1; dy <= 1; dy++) { int iy = y + dy; int ioffset; if (0 <= iy && iy < height) { ioffset = iy * width; for (int dx = -1; dx <= 1; dx++) { int ix = x + dx; if (0 <= ix && ix < width) { pixel = PixelUtils.combinePixels(pixel, inPixels[ioffset + ix], PixelUtils.MIN); } } } } outPixels[index++] = pixel; } } return outPixels; }
public int filterRGB(int x, int y, int rgb) { int a = rgb & 0xff000000; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; int nr = PixelUtils.clamp( (intoR * (blueGreen * g + (255 - blueGreen) * b) / 255 + (255 - intoR) * r) / 255); int ng = PixelUtils.clamp( (intoG * (redBlue * b + (255 - redBlue) * r) / 255 + (255 - intoG) * g) / 255); int nb = PixelUtils.clamp( (intoB * (greenRed * r + (255 - greenRed) * g) / 255 + (255 - intoB) * b) / 255); return a | (nr << 16) | (ng << 8) | nb; }
@Override protected int[] filterPixels(int width, int height, int[] inPixels, Rect transformedSpace) { Histogram histogram = new Histogram(inPixels, width, height, 0, width); int i, j; if (histogram.getNumSamples() > 0) { lut = new int[3][256]; float low = lowLevel * 255; float high = highLevel * 255; if (low == high) high++; for (i = 0; i < 3; i++) { for (j = 0; j < 256; j++) lut[i][j] = PixelUtils.clamp( (int) (255 * (lowOutputLevel + (highOutputLevel - lowOutputLevel) * (j - low) / (high - low)))); } } else lut = null; i = 0; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { inPixels[i] = filterRGB(x, y, inPixels[i]); i++; } lut = null; return inPixels; }
/** Convolve with a kernel consisting of one row */ public static void convolveH( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int cols = kernel.getWidth(); int cols2 = cols / 2; for (int y = 0; y < height; y++) { int ioffset = y * width; for (int x = 0; x < width; x++) { float r = 0, g = 0, b = 0, a = 0; int moffset = cols2; for (int col = -cols2; col <= cols2; col++) { float f = matrix[moffset + col]; if (f != 0) { int ix = x + col; if (ix < 0) { if (edgeAction == CLAMP_EDGES) ix = 0; else if (edgeAction == WRAP_EDGES) ix = (x + width) % width; } else if (ix >= width) { if (edgeAction == CLAMP_EDGES) ix = width - 1; else if (edgeAction == WRAP_EDGES) ix = (x + width) % width; } int rgb = inPixels[ioffset + ix]; a += f * ((rgb >> 24) & 0xff); r += f * ((rgb >> 16) & 0xff); g += f * ((rgb >> 8) & 0xff); b += f * (rgb & 0xff); } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5)) : 0xff; int ir = PixelUtils.clamp((int) (r + 0.5)); int ig = PixelUtils.clamp((int) (g + 0.5)); int ib = PixelUtils.clamp((int) (b + 0.5)); outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib; } } }
public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); int type = src.getType(); WritableRaster srcRaster = src.getRaster(); if (dst == null) dst = createCompatibleDestImage(src, null); WritableRaster dstRaster = dst.getRaster(); if (destination != null) { width = Math.min(width, destination.getWidth()); height = Math.min(height, destination.getWidth()); int[] pixels1 = null; int[] pixels2 = null; for (int y = 0; y < height; y++) { pixels1 = getRGB(src, 0, y, width, 1, pixels1); pixels2 = getRGB(destination, 0, y, width, 1, pixels2); for (int x = 0; x < width; x++) { int rgb1 = pixels1[x]; int rgb2 = pixels2[x]; int a1 = (rgb1 >> 24) & 0xff; int r1 = (rgb1 >> 16) & 0xff; int g1 = (rgb1 >> 8) & 0xff; int b1 = rgb1 & 0xff; int a2 = (rgb2 >> 24) & 0xff; int r2 = (rgb2 >> 16) & 0xff; int g2 = (rgb2 >> 8) & 0xff; int b2 = rgb2 & 0xff; r1 = PixelUtils.clamp(ImageMath.lerp(interpolation, r1, r2)); g1 = PixelUtils.clamp(ImageMath.lerp(interpolation, g1, g2)); b1 = PixelUtils.clamp(ImageMath.lerp(interpolation, b1, b2)); pixels1[x] = (a1 << 24) | (r1 << 16) | (g1 << 8) | b1; } setRGB(dst, 0, y, width, 1, pixels1); } } return dst; }
private void conicalGradient(int[] pixels, int y, int w, int h) { int off = 0; float angle0 = (float) Math.atan2(p2.x - p1.x, p2.y - p1.y); for (int x = 0; x < w; x++) { float angle = (float) (Math.atan2(x - p1.x, y - p1.y) - angle0) / (ImageMath.TWO_PI); angle += 1.0f; angle %= 1.0f; if (type == BICONICAL) angle = ImageMath.triangle(angle); int rgb = colormap.getColor(map(angle)); pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; } }
private void squareGradient(int[] pixels, int y, int w, int h) { int off = 0; float radius = Math.max(Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); for (int x = 0; x < w; x++) { float distance = Math.max(Math.abs(x - p1.x), Math.abs(y - p1.y)); float ratio = distance / radius; if (repeat) ratio = ratio % 2; else if (ratio > 1.0) ratio = 1.0f; int rgb = colormap.getColor(map(ratio)); pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; } }
private void repeatGradient(int[] pixels, int w, int h, float rowrel, float dx, float dy) { int off = 0; for (int y = 0; y < h; y++) { float colrel = rowrel; int j = w; int rgb; while (--j >= 0) { if (type == BILINEAR) rgb = colormap.getColor(map(ImageMath.triangle(colrel))); else rgb = colormap.getColor(map(ImageMath.mod(colrel, 1.0f))); pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; colrel += dx; } rowrel += dy; } }
public static void convolveHV( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int ioffset; int index = 0; float[] matrix = kernel.getKernelData(null); int rows = kernel.getHeight(); int cols = kernel.getWidth(); int rows2 = rows / 2; int cols2 = cols / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float r = 0.0F; float g = 0.0F; float b = 0.0F; float a = 0.0F; for (int row = -rows2; row <= rows2; row++) { int iy = y + row; if ((0 <= iy) && (iy < height)) { ioffset = iy * width; } else { if (edgeAction == CLAMP_EDGES) { ioffset = y * width; } else { if (edgeAction != WRAP_EDGES) { continue; } ioffset = (iy + height) % height * width; } } int moffset = cols * (row + rows2) + cols2; for (int col = -cols2; col <= cols2; col++) { float f = matrix[(moffset + col)]; if (f != 0.0F) { int ix = x + col; if ((0 > ix) || (ix >= width)) { if (edgeAction == CLAMP_EDGES) { ix = x; } else { if (edgeAction != WRAP_EDGES) { continue; } ix = (x + width) % width; } } int rgb = inPixels[(ioffset + ix)]; a += f * (rgb >> 24 & 0xFF); r += f * (rgb >> 16 & 0xFF); g += f * (rgb >> 8 & 0xFF); b += f * (rgb & 0xFF); } } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5D)) : 255; int ir = PixelUtils.clamp((int) (r + 0.5D)); int ig = PixelUtils.clamp((int) (g + 0.5D)); int ib = PixelUtils.clamp((int) (b + 0.5D)); outPixels[(index++)] = (ia << 24 | ir << 16 | ig << 8 | ib); } } }
public static void convolveV( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int ioffset; int index = 0; float[] matrix = kernel.getKernelData(null); int rows = kernel.getHeight(); int rows2 = rows / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float r = 0.0F; float g = 0.0F; float b = 0.0F; float a = 0.0F; for (int row = -rows2; row <= rows2; row++) { int iy = y + row; if (iy < 0) { if (edgeAction == CLAMP_EDGES) { ioffset = 0; } else { if (edgeAction == WRAP_EDGES) { ioffset = (y + height) % height * width; } else { ioffset = iy * width; } } } else { if (iy >= height) { if (edgeAction == CLAMP_EDGES) { ioffset = (height - 1) * width; } else { if (edgeAction == WRAP_EDGES) { ioffset = (y + height) % height * width; } else { ioffset = iy * width; } } } else { ioffset = iy * width; } } float f = matrix[(row + rows2)]; if (f != 0.0F) { int rgb = inPixels[(ioffset + x)]; a += f * (rgb >> 24 & 0xFF); r += f * (rgb >> 16 & 0xFF); g += f * (rgb >> 8 & 0xFF); b += f * (rgb & 0xFF); } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5D)) : 255; int ir = PixelUtils.clamp((int) (r + 0.5D)); int ig = PixelUtils.clamp((int) (g + 0.5D)); int ib = PixelUtils.clamp((int) (b + 0.5D)); outPixels[(index++)] = (ia << 24 | ir << 16 | ig << 8 | ib); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bar_plot_example); // initialize our XYPlot reference: plot = (XYPlot) findViewById(R.id.plot); formatter1 = new MyBarFormatter(Color.rgb(100, 150, 100), Color.LTGRAY); formatter1.setMarginLeft(PixelUtils.dpToPix(1)); formatter1.setMarginRight(PixelUtils.dpToPix(1)); formatter2 = new MyBarFormatter(Color.rgb(100, 100, 150), Color.LTGRAY); formatter2.setMarginLeft(PixelUtils.dpToPix(1)); formatter2.setMarginRight(PixelUtils.dpToPix(1)); selectionFormatter = new MyBarFormatter(Color.YELLOW, Color.WHITE); selectionWidget = new TextLabelWidget( plot.getLayoutManager(), NO_SELECTION_TXT, new Size( PixelUtils.dpToPix(100), SizeMode.ABSOLUTE, PixelUtils.dpToPix(100), SizeMode.ABSOLUTE), TextOrientation.HORIZONTAL); selectionWidget.getLabelPaint().setTextSize(PixelUtils.dpToPix(16)); // add a dark, semi-transparent background to the selection label widget: Paint p = new Paint(); p.setARGB(100, 0, 0, 0); selectionWidget.setBackgroundPaint(p); selectionWidget.position( 0, HorizontalPositioning.RELATIVE_TO_CENTER, PixelUtils.dpToPix(45), VerticalPositioning.ABSOLUTE_FROM_TOP, Anchor.TOP_MIDDLE); selectionWidget.pack(); // reduce the number of range labels plot.setLinesPerRangeLabel(3); plot.setRangeLowerBoundary(0, BoundaryMode.FIXED); plot.setLinesPerDomainLabel(2); // setup checkbox listers: series1CheckBox = (CheckBox) findViewById(R.id.s1CheckBox); series1CheckBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { onS1CheckBoxClicked(b); } }); series2CheckBox = (CheckBox) findViewById(R.id.s2CheckBox); series2CheckBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { onS2CheckBoxClicked(b); } }); plot.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { onPlotClicked(new PointF(motionEvent.getX(), motionEvent.getY())); } return true; } }); spRenderStyle = (Spinner) findViewById(R.id.spRenderStyle); ArrayAdapter<BarRenderer.BarOrientation> adapter = new ArrayAdapter<BarRenderer.BarOrientation>( this, android.R.layout.simple_spinner_item, BarRenderer.BarOrientation.values()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spRenderStyle.setAdapter(adapter); spRenderStyle.setSelection(BarRenderer.BarOrientation.OVERLAID.ordinal()); spRenderStyle.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { updatePlot(); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); spWidthStyle = (Spinner) findViewById(R.id.spWidthStyle); ArrayAdapter<BarRenderer.BarGroupWidthMode> adapter1 = new ArrayAdapter<BarRenderer.BarGroupWidthMode>( this, android.R.layout.simple_spinner_item, BarRenderer.BarGroupWidthMode.values()); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spWidthStyle.setAdapter(adapter1); spWidthStyle.setSelection(BarRenderer.BarGroupWidthMode.FIXED_WIDTH.ordinal()); spWidthStyle.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (BarRenderer.BarGroupWidthMode.FIXED_WIDTH.equals(spWidthStyle.getSelectedItem())) { sbFixedWidth.setVisibility(View.VISIBLE); sbVariableWidth.setVisibility(View.INVISIBLE); } else { sbFixedWidth.setVisibility(View.INVISIBLE); sbVariableWidth.setVisibility(View.VISIBLE); } updatePlot(); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); spSeriesSize = (Spinner) findViewById(R.id.spSeriesSize); ArrayAdapter<SeriesSize> adapter11 = new ArrayAdapter<SeriesSize>( this, android.R.layout.simple_spinner_item, SeriesSize.values()); adapter11.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spSeriesSize.setAdapter(adapter11); spSeriesSize.setSelection(SeriesSize.TEN.ordinal()); spSeriesSize.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { final SeriesSize selectedSize = (SeriesSize) arg0.getSelectedItem(); switch (selectedSize) { case TEN: series1Numbers = series1Numbers10; series2Numbers = series2Numbers10; break; case TWENTY: series1Numbers = series1Numbers20; series2Numbers = series2Numbers20; break; case SIXTY: series1Numbers = series1Numbers60; series2Numbers = series2Numbers60; break; default: break; } updatePlot(selectedSize); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); sbFixedWidth = (SeekBar) findViewById(R.id.sbFixed); sbFixedWidth.setProgress(50); sbFixedWidth.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { updatePlot(); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); sbVariableWidth = (SeekBar) findViewById(R.id.sbVariable); sbVariableWidth.setProgress(1); sbVariableWidth.setVisibility(View.INVISIBLE); sbVariableWidth.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { updatePlot(); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); plot.getGraph() .getLineLabelStyle(XYGraphWidget.Edge.BOTTOM) .setFormat( new NumberFormat() { @Override public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) { int year = (int) (value + 0.5d) / 12; int month = (int) ((value + 0.5d) % 12); return new StringBuffer( DateFormatSymbols.getInstance().getShortMonths()[month] + " '0" + year); } @Override public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) { throw new UnsupportedOperationException("Not yet implemented."); } @Override public Number parse(String string, ParsePosition position) { throw new UnsupportedOperationException("Not yet implemented."); } }); updatePlot(); }
public void quantize( int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) { int count = width * height; Quantizer quantizer = new OctTreeQuantizer(); quantizer.setup(numColors); quantizer.addPixels(inPixels, 0, count); int[] table = quantizer.buildColorTable(); if (!dither) { for (int i = 0; i < count; i++) outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])]; } else { int index = 0; for (int y = 0; y < height; y++) { boolean reverse = serpentine && (y & 1) == 1; int direction; if (reverse) { index = y * width + width - 1; direction = -1; } else { index = y * width; direction = 1; } for (int x = 0; x < width; x++) { int rgb1 = inPixels[index]; int rgb2 = table[quantizer.getIndexForColor(rgb1)]; outPixels[index] = rgb2; int r1 = (rgb1 >> 16) & 0xff; int g1 = (rgb1 >> 8) & 0xff; int b1 = rgb1 & 0xff; int r2 = (rgb2 >> 16) & 0xff; int g2 = (rgb2 >> 8) & 0xff; int b2 = rgb2 & 0xff; int er = r1 - r2; int eg = g1 - g2; int eb = b1 - b2; for (int i = -1; i <= 1; i++) { int iy = i + y; if (0 <= iy && iy < height) { for (int j = -1; j <= 1; j++) { int jx = j + x; if (0 <= jx && jx < width) { int w; if (reverse) w = matrix[(i + 1) * 3 - j + 1]; else w = matrix[(i + 1) * 3 + j + 1]; if (w != 0) { int k = reverse ? index - j : index + j; rgb1 = inPixels[k]; r1 = (rgb1 >> 16) & 0xff; g1 = (rgb1 >> 8) & 0xff; b1 = rgb1 & 0xff; r1 += er * w / sum; g1 += eg * w / sum; b1 += eb * w / sum; inPixels[k] = (PixelUtils.clamp(r1) << 16) | (PixelUtils.clamp(g1) << 8) | PixelUtils.clamp(b1); } } } } } index += direction; } } } }
/*
private int average(int rgb1, int rgb2) { return PixelUtils.combinePixels(rgb1, rgb2, PixelUtils.AVERAGE); }
private int displacementMap(int x, int y) { return PixelUtils.clamp((int) (127 * (1 + Noise.noise2(x / xScale, y / xScale)))); }
public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); int[] pixels = new int[width]; int[] srcPixels = new int[width]; BufferedImage rays = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int threshold3 = (int) (threshold * 3 * 255); for (int y = 0; y < height; y++) { getRGB(src, 0, y, width, 1, pixels); for (int x = 0; x < width; x++) { int rgb = pixels[x]; int a = rgb & 0xff000000; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; int l = r + g + b; if (l < threshold3) pixels[x] = 0xff000000; else { l /= 3; pixels[x] = a | (l << 16) | (l << 8) | l; } } setRGB(rays, 0, y, width, 1, pixels); } rays = super.filter(rays, null); for (int y = 0; y < height; y++) { getRGB(rays, 0, y, width, 1, pixels); getRGB(src, 0, y, width, 1, srcPixels); for (int x = 0; x < width; x++) { int rgb = pixels[x]; int a = rgb & 0xff000000; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; if (colormap != null) { int l = r + g + b; rgb = colormap.getColor(l * strength * (1 / 3f)); } else { r = PixelUtils.clamp((int) (r * strength)); g = PixelUtils.clamp((int) (g * strength)); b = PixelUtils.clamp((int) (b * strength)); rgb = a | (r << 16) | (g << 8) | b; } pixels[x] = rgb; } setRGB(rays, 0, y, width, 1, pixels); } if (dst == null) dst = createCompatibleDestImage(src, null); Graphics2D g = dst.createGraphics(); if (!raysOnly) { g.setComposite(AlphaComposite.SrcOver); g.drawRenderedImage(src, null); } g.setComposite(MiscComposite.getInstance(MiscComposite.ADD, opacity)); g.drawRenderedImage(rays, null); g.dispose(); return dst; }