Java Code Examples for net.imglib2.type.numeric.ARGBType#get()

The following examples show how to use net.imglib2.type.numeric.ARGBType#get() . 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: CompositeProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void accumulate(final Cursor<? extends ARGBType>[] accesses, final ARGBType t)
{
	t.set(0);
	for (int i = 0; i < composites.size(); ++i)
		composites.get(i).compose(t, accesses[i].get());
	final int nonpre = t.get();
	t.set(PixelUtils.NonPretoPre(nonpre));
	//		@SuppressWarnings( "restriction" )
	//		final int pre = PixelUtils.NonPretoPre( nonpre );
	//		final int a = nonpre & 0xff;
	//		if ( a == 0xff )
	//			return;
	//		if ( a == 0x00 )
	//			return;
	//		int r = nonpre >> 24 & 0xff;
	//		int g = nonpre >> 16 & 0xff;
	//		int b = nonpre >> 8 & 0xff;
	//		r = ( r * a + 0x7f ) / 0xff;
	//		g = ( g * a + 0x7f ) / 0xff;
	//		b = ( b * a + 0x7f ) / 0xff;
	//		final int pre = a << 0 | r << 24 | g << 16 | b << 8;
	//		final int pre = PixelUtils.NonPretoPre( nonpre );
	//		t.set( pre );
}
 
Example 2
Source File: ARGBCompositeAlphaAdd.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void compose(final ARGBType a, final ARGBType b)
{
	final int argbA = a.get();
	final int argbB = b.get();

	final int rA = ARGBType.red(argbA);
	final int rB = ARGBType.red(argbB);
	final int gA = ARGBType.green(argbA);
	final int gB = ARGBType.green(argbB);
	final int bA = ARGBType.blue(argbA);
	final int bB = ARGBType.blue(argbB);

	final double aA = ARGBType.alpha(argbA) / 255.0;
	final double aB = ARGBType.alpha(argbB) / 255.0;
	//		final double aB = ( rB == gB || gB == bB ) ? ARGBType.alpha( argbB ) / 255.0 : ARGBType.alpha( argbB )
	// / 255.0 * 0.125;

	final double aTarget = aA + aB - aA * aB;

	final int rTarget = Math.min(255, (int) Math.round(rA + rB * aB));
	final int gTarget = Math.min(255, (int) Math.round(gA + gB * aB));
	final int bTarget = Math.min(255, (int) Math.round(bA + bB * aB));

	a.set(ARGBType.rgba(rTarget, gTarget, bTarget, (int) (aTarget * 255)));
}
 
Example 3
Source File: DerivedMatchGroup.java    From render with GNU General Public License v2.0 6 votes vote down vote up
private List<Integer> getSetIndexesForPoints(final RealPointSampleList<ARGBType> largestSetIndexSamples,
                                             final List<RealPoint> otherSetPoints) {

    final List<Integer> setIndexList = new ArrayList<>();

    final KDTree<ARGBType> kdTree = new KDTree<>(largestSetIndexSamples);
    final NearestNeighborSearch<ARGBType> nnSearchSamples = new NearestNeighborSearchOnKDTree<>(kdTree);

    Sampler<ARGBType> sampler;
    ARGBType sampleItem;
    int nnSetIndex;
    for (final RealPoint otherPoint : otherSetPoints) {
        nnSearchSamples.search(otherPoint);
        sampler = nnSearchSamples.getSampler();

        sampleItem = sampler.get();
        nnSetIndex = sampleItem.get();
        setIndexList.add(nnSetIndex);
    }

    return setIndexList;
}
 
Example 4
Source File: Colors.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public static String toHTML(final ARGBType color)
{
	final int c = color.get();
	return String.format(
			"#%02X%02X%02X",
			ARGBType.red(c),
			ARGBType.green(c),
			ARGBType.blue(c)
	                    );

}
 
Example 5
Source File: LinearIntensityMap.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static protected < T extends RealType< T > > void mapARGB(
		final IterableInterval< ARGBType > image,
		final IterableInterval< RealComposite< T > > coefficients )
{
	final Cursor< ARGBType > cs = image.cursor();
	final Cursor< RealComposite< T > > ct = coefficients.cursor();

	while ( cs.hasNext() )
	{
		final RealComposite< T > t = ct.next();
		final double alpha = t.get( 0 ).getRealDouble();
		final double beta = t.get( 1 ).getRealDouble();

		final ARGBType s = cs.next();
		final int argb = s.get();
		final int a = ( ( argb >> 24 ) & 0xff );
		final double r = ( ( argb >> 16 ) & 0xff ) * alpha + beta;
		final double g = ( ( argb >> 8 ) & 0xff ) * alpha + beta;
		final double b = ( argb & 0xff ) * alpha + beta;

		s.set(
				( a << 24 ) |
				( ( r < 0 ? 0 : r > 255 ? 255 : ( int )( r + 0.5 ) ) << 16 ) |
				( ( g < 0 ? 0 : g > 255 ? 255 : ( int )( g + 0.5 ) ) << 8 ) |
				( b < 0 ? 0 : b > 255 ? 255 : ( int )( b + 0.5 ) ) );
	}
}
 
Example 6
Source File: SimpleInterruptibleProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Render the 2D target image by copying values from the source. Source can have more dimensions than the target.
 * Target coordinate <em>(x,y)</em> is copied from source coordinate <em>(x,y,0,...,0)</em>.
 *
 * @return true if rendering was completed (all target pixels written). false if rendering was interrupted.
 */
@Override
public boolean map()
{
	interrupted.set(false);

	final StopWatch stopWatch = new StopWatch();
	stopWatch.start();

	min[0] = target.min(0);
	min[1] = target.min(1);
	max[0] = target.max(0);
	max[1] = target.max(1);

	final long cr = -target.dimension(0);

	final int width  = (int) target.dimension(0);
	final int height = (int) target.dimension(1);

	final boolean         createExecutor = executorService == null;
	final ExecutorService ex             = createExecutor
	                                       ? Executors.newFixedThreadPool(numThreads)
	                                       : executorService;
	final int             numTasks;
	if (numThreads > 1)
	{
		numTasks = Math.min(numThreads * 10, height);
	}
	else
		numTasks = 1;
	final double                    taskHeight = (double) height / numTasks;
	final ArrayList<Callable<Void>> tasks      = new ArrayList<>(numTasks);
	for (int taskNum = 0; taskNum < numTasks; ++taskNum)
	{
		final long myMinY   = min[1] + (int) (taskNum * taskHeight);
		final long myHeight = (taskNum == numTasks - 1
		                       ? height
		                       : (int) ((taskNum + 1) * taskHeight)) - myMinY - min[1];

		final Callable<Void> r = () -> {
			if (interrupted.get())
				return null;

			System.out.println("WTF!");
			final RandomAccess<A>        sourceRandomAccess = source.randomAccess(
					SimpleInterruptibleProjectorPreMultiply.this);
			final RandomAccess<ARGBType> targetRandomAccess = target.randomAccess(target);

			sourceRandomAccess.setPosition(min);
			sourceRandomAccess.setPosition(myMinY, 1);
			targetRandomAccess.setPosition(min[0], 0);
			targetRandomAccess.setPosition(myMinY, 1);
			for (int y = 0; y < myHeight; ++y)
			{
				if (interrupted.get())
					return null;
				for (int x = 0; x < width; ++x)
				{
					final ARGBType argb = targetRandomAccess.get();
					converter.convert(sourceRandomAccess.get(), argb);
					final int nonpre = argb.get();
					argb.set(PixelUtils.NonPretoPre(nonpre));
					sourceRandomAccess.fwd(0);
					targetRandomAccess.fwd(0);
				}
				sourceRandomAccess.move(cr, 0);
				targetRandomAccess.move(cr, 0);
				sourceRandomAccess.fwd(1);
				targetRandomAccess.fwd(1);
			}
			return null;
		};
		tasks.add(r);
	}
	try
	{
		ex.invokeAll(tasks);
	} catch (final InterruptedException e)
	{
		Thread.currentThread().interrupt();
	}
	if (createExecutor)
		ex.shutdown();

	lastFrameRenderNanoTime = stopWatch.nanoTime();

	return !interrupted.get();
}
 
Example 7
Source File: ARGBCompositeAlphaYCbCr.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void compose(final ARGBType a, final ARGBType b)
{
	final int argbA = a.get();
	final int argbB = b.get();

	final double rA = ARGBType.red(argbA) / 255.0;
	final double rB = ARGBType.red(argbB) / 255.0;
	final double gA = ARGBType.green(argbA) / 255.0;
	final double gB = ARGBType.green(argbB) / 255.0;
	final double bA = ARGBType.blue(argbA) / 255.0;
	final double bB = ARGBType.blue(argbB) / 255.0;

	final double aA = ARGBType.alpha(argbA) / 255.0;
	final double aB = ARGBType.alpha(argbB) / 255.0;
	//		final double aB = ( rB == gB || gB == bB ) ? ARGBType.alpha( argbB ) / 255.0 * 0.5 : ARGBType.alpha(
	// argbB ) / 255.0 * 0.125;

	final double aTarget = aA + aB - aA * aB;

	final double yA  = rgb2y(rA, gA, bA);
	final double cbA = rgb2cb(rA, gA, bA);
	final double crA = rgb2cr(rA, gA, bA);

	final double cbB = rgb2cb(rB, gB, bB);
	final double crB = rgb2cr(rB, gB, bB);

	final double aBInv = 1.0 - aB;

	final double cbTarget = cbA * aBInv + cbB * aB;
	final double crTarget = crA * aBInv + crB * aB;

	final double rTarget = ycbcr2r(yA, cbTarget, crTarget);
	final double gTarget = ycbcr2g(yA, cbTarget, crTarget);
	final double bTarget = ycbcr2b(yA, cbTarget, crTarget);

	a.set(ARGBType.rgba(
			Math.max(0, Math.min(255, (int) Math.round(rTarget * 255))),
			Math.max(0, Math.min(255, (int) Math.round(gTarget * 255))),
			Math.max(0, Math.min(255, (int) Math.round(bTarget * 255))),
			(int) (aTarget * 255)
	                   ));
}