CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-workerpool

Offload tasks to a pool of workers on node.js and in the browser

Overall
score

95%

Overview
Eval results
Files

task.mdevals/scenario-7/

Image Processing Worker Pool

Create a worker pool system that processes large image buffers efficiently using parallel workers.

Problem Description

You need to build a system that can process multiple large image buffers in parallel. Each image is represented as a raw RGBA pixel buffer (4 bytes per pixel). The processing involves applying a brightness adjustment to each pixel in the image.

Your system should:

  1. Create a worker pool that can process images in parallel
  2. Efficiently transfer large image buffers to workers without copying overhead
  3. Process the image data by adjusting brightness (adding a delta value to each RGB channel)
  4. Return the processed image buffers back to the main thread efficiently

Requirements

Main Application (index.js)

Create a main application that:

  • Creates a worker pool
  • Generates sample image data (simulated as ArrayBuffer with RGBA pixel data)
  • Submits multiple images for processing with brightness adjustments
  • Receives processed results
  • Logs processing statistics

Worker Implementation (image-worker.js)

Create a worker script that:

  • Defines a processBrightness function that takes an image buffer and brightness delta
  • Modifies the RGB values of each pixel by the delta amount (clamped to 0-255)
  • Returns the modified buffer

Test Cases

@test Test Case 1: Single Image Processing

Input:

  • Image: 1920x1080 pixels (8,294,400 bytes RGBA buffer)
  • Brightness delta: +20

Expected Output:

  • Processed buffer with same dimensions
  • Each RGB channel increased by 20 (clamped at 255)
  • Alpha channel unchanged

@test Test Case 2: Multiple Images in Parallel

Input:

  • 4 images of 1920x1080 pixels each
  • Different brightness deltas: +10, +30, -20, +50

Expected Output:

  • All 4 images processed with respective brightness adjustments
  • Processing should complete faster than sequential processing
  • All buffers returned correctly

@test Test Case 3: Verify Zero-Copy Transfer

Input:

  • One 4K image (3840x2160 pixels = 33,177,600 bytes)

Expected Behavior:

  • After transferring buffer to worker, the original buffer in main thread should be detached (length = 0)
  • This verifies the buffer was transferred, not copied

Implementation Notes

  • Use ArrayBuffer with Uint8ClampedArray view for pixel data
  • RGBA format: 4 bytes per pixel (Red, Green, Blue, Alpha)
  • Brightness adjustment: Add delta to R, G, B channels (leave Alpha unchanged)
  • Clamp values to valid range 0-255
  • Focus on efficient data transfer for large buffers

Output Format

Your implementation should log:

Processing image 1 (1920x1080)...
Processing image 2 (1920x1080)...
Image 1 completed
Image 2 completed
All images processed successfully

Dependencies { .dependencies }

workerpool { .dependency }

Provides worker pool functionality for parallel task execution.

Files { .files }

index.js { .file }

Main application that creates the worker pool and processes images.

image-worker.js { .file }

Worker script that implements the image brightness processing logic.

index.test.js { .file }

Test suite that validates the image processing functionality.

Install with Tessl CLI

npx tessl i tessl/npm-workerpool

tile.json