### Question:
AveragedChannelMipmapSource implements MipmapSource { @Override public ChannelMap getChannels(final int mipmapLevel) throws IllegalArgumentException { final long start = System.currentTimeMillis(); final ChannelMap sourceChannels = source.getChannels(mipmapLevel); final ImageProcessorWithMasks firstSourceChannel = sourceChannels.getFirstChannel(); final int width = firstSourceChannel.ip.getWidth(); final int height = firstSourceChannel.ip.getHeight(); final int pixelCount = width * height; final ImageProcessorWithMasks averagedChannel = new ImageProcessorWithMasks(firstSourceChannel.ip.createProcessor(width, height), new ByteProcessor(width, height), null); for (final String channelName : channelNamesAndWeights.getNames()) { final ImageProcessorWithMasks sourceChannel = sourceChannels.get(channelName); if (sourceChannel != null) { final float sourceWeight = channelNamesAndWeights.getWeight(channelName).floatValue(); for (int i = 0; i < pixelCount; i++) { averageChannelAndAlphaPixels(sourceChannel, sourceWeight, averagedChannel, i); } } } final ChannelMap averagedChannelMap = new ChannelMap(averagedChannelName, averagedChannel); final long stop = System.currentTimeMillis(); LOG.debug("getChannels: {} took {} milliseconds to average {} channels for level {}", getSourceName(), stop - start, channelNamesAndWeights.size(), mipmapLevel); return averagedChannelMap; } AveragedChannelMipmapSource(final String averagedChannelName,
                                       final MipmapSource source,
                                       final ChannelNamesAndWeights channelNamesAndWeights); @Override String getSourceName(); @Override int getFullScaleWidth(); @Override int getFullScaleHeight(); @Override ChannelMap getChannels(final int mipmapLevel); static void averageChannelAndAlphaPixels(final ImageProcessorWithMasks source,
                                                    final float sourceWeight,
                                                    final ImageProcessorWithMasks target,
                                                    final int pixelIndex);  }### Answer:
@Test public void testGetChannels() throws Exception { final String[] args = { "--tile_spec_url", "src/test/resources/multichannel-test/test_2_channels.json", "--channels", firstChannelName + "__0.7__" + secondChannelName + "__0.3", "--out", "not-applicable-but-required-file-name.png", "--x", "650", "--y", "1600", "--width", "4000", "--height", "2200", "--scale", "0.25" }; final RenderParameters renderParameters = RenderParameters.parseCommandLineArgs(args); final RenderedCanvasMipmapSource renderedCanvasMipmapSource = new RenderedCanvasMipmapSource(renderParameters, ImageProcessorCache.DISABLED_CACHE); final ImageProcessorWithMasks onlySecondChannel = getAveragedChannel(secondChannelName, renderedCanvasMipmapSource, 0.0, 1.0); final ImageProcessorWithMasks averagedChannel = getAveragedChannel("averaged_75_25", renderedCanvasMipmapSource, 0.75, 0.25); final int pixelIndex = 100000; Assert.assertNotSame("channel intensity should not match", onlySecondChannel.ip.getf(pixelIndex), averagedChannel.ip.getf(pixelIndex)); final BufferedImage image = ArgbRenderer.targetToARGBImage(averagedChannel, false); Assert.assertNotNull("averaged image not rendered", image); }