Change resampling method when resizing

Hi,

Is there a way to change the resampling method when resizing a PGraphics object?

I would like to have the nearest-neighbor interpolation in the following code:

void setup() {
  size(512, 512);
  
  PGraphics pg = createGraphics(50, 50);
  
  pg.beginDraw();
  pg.background(20);
  pg.noStroke();
  pg.fill(200);
  pg.ellipse(25, 25, 25, 25);
  pg.endDraw();
  
  image(pg, 0, 0, width, height);
}
1 Like

Dunno. You can roll your own?

void setup() {
  size(512, 512);

  PGraphics pg = createGraphics(50, 50);

  pg.beginDraw();
  pg.background(20);
  pg.noStroke();
  pg.fill(200);
  pg.ellipse(25, 25, 25, 25);
  pg.endDraw();

  loadPixels();
  for ( int x = 0; x < width; x++) {
    for ( int y = 0; y < height; y++) {
      pixels[x + width*y] = pg.get( floor(x * pg.width/float(width)), floor(y * pg.height/float(height)) );
    }
  }
  updatePixels();
}

void draw() {
}
1 Like

Thanks @TfGuy44,

It is of course a solution but I was thinking something more general. Like for example beeing able to switch between the most common algorithms:

  • Nearest-neighbor interpolation
  • Bilinear algorithms
  • Bicubic algorithms
  • And maybe some more.

Processing.org/reference/smooth_.html

2 Likes

If you are looking to play with options beyond the OpenGL smooth sampling rate in smooth() and want to try rolling your own, there is also a demo on the old forum of FXAA (Fast_approximate_anti-aliasing) implemented as a PShader:

If you get really into it you could make it a library. My first thought is that pixel-aesthetic games might be one example of a use case where someone might want fine control over upscaling or downscaling effects.

2 Likes