ImageDownscaleStage extends PronghornStage { @Override public void run() { while (outputsHaveRoom() && PipeReader.tryReadFragment(input)) { int msgIdx = PipeReader.getMsgIdx(input); if (msgIdx == ImageSchema.MSG_FRAMECHUNK_2) { processChunk(); } else if (msgIdx == ImageSchema.MSG_FRAMESTART_1) { processFrameStart(); } PipeReader.releaseReadLock(input); } } ImageDownscaleStage(GraphManager graphManager, Pipe<ImageSchema> input, Pipe<ImageSchema>[] outputs, int outputWidth, int outputHeight); static ImageDownscaleStage newInstance(GraphManager graphManager, Pipe<ImageSchema> input, Pipe<ImageSchema>[] outputs, int outputWidth, int outputHeight); @Override void run(); static final int R_OUTPUT_IDX; static final int G_OUTPUT_IDX; static final int B_OUTPUT_IDX; static final int MONO_OUTPUT_IDX; static final byte[] INPUT_ENCODING; static final byte[] R_OUTPUT_ENCODING; static final byte[] G_OUTPUT_ENCODING; static final byte[] B_OUTPUT_ENCODING; static final byte[] MONO_OUTPUT_ENCODING; static final byte[][] OUTPUT_ENCODING_LOOKUP; }
@Test public void shouldDownscaleImagesTest() { int iterations = 5; int j = iterations; while (--j>=0) { setup(); NonThreadScheduler scheduler = new NonThreadScheduler(gm); scheduler.startup(); boolean allWritten = false; while (!allWritten) { scheduler.run(); allWritten = true; for (int i = 0; i < downsampleOutputPipes.length; i++) { switch (i) { case ImageDownscaleStage.R_OUTPUT_IDX: readFromDownsamplePipe(downsampleOutputPipes[i], downsamplePipeReaderStates[i], ImageDownscaleStage.R_OUTPUT_ENCODING); break; case ImageDownscaleStage.G_OUTPUT_IDX: readFromDownsamplePipe(downsampleOutputPipes[i], downsamplePipeReaderStates[i], ImageDownscaleStage.G_OUTPUT_ENCODING); break; case ImageDownscaleStage.B_OUTPUT_IDX: readFromDownsamplePipe(downsampleOutputPipes[i], downsamplePipeReaderStates[i], ImageDownscaleStage.B_OUTPUT_ENCODING); break; case ImageDownscaleStage.MONO_OUTPUT_IDX: readFromDownsamplePipe(downsampleOutputPipes[i], downsamplePipeReaderStates[i], ImageDownscaleStage.MONO_OUTPUT_ENCODING); break; } allWritten = allWritten && downsamplePipeReaderStates[i].framesProcessed > 0; } } for (int i = 0; i < downsampleOutputPipes.length; i++) { Path filePath = null; switch (i) { case ImageDownscaleStage.R_OUTPUT_IDX: filePath = Paths.get("src", "test", "images", "cat1-320-240.r8"); break; case ImageDownscaleStage.G_OUTPUT_IDX: filePath = Paths.get("src", "test", "images", "cat1-320-240.g8"); break; case ImageDownscaleStage.B_OUTPUT_IDX: filePath = Paths.get("src", "test", "images", "cat1-320-240.b8"); break; case ImageDownscaleStage.MONO_OUTPUT_IDX: filePath = Paths.get("src", "test", "images", "cat1-320-240.mono"); break; } try { byte[] fileBytes = Files.readAllBytes(filePath); Assert.assertTrue(Arrays.equals(fileBytes, downsamplePipeReaderStates[i].currentFrame)); } catch (IOException e) { Assert.fail(e.getMessage()); } } } }