We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
img scale artifacts (Read 1037 times)
img scale artifacts
Oct 23rd, 2007, 10:30pm
 
if you draw 80x80 pixels into an img and then scale that img by a factor 2, you get a blurred variant compared to drawing rect of 2x2 onto the screen...
why?

F
Re: img scale artifacts
Reply #1 - Oct 24th, 2007, 3:58pm
 
hi,

not sure if i understand... but isn't it just because we're working with pixels here, not vectors?
Or else, post a code snippet demonstrating the problem you describe.
Re: img scale artifacts
Reply #2 - Oct 24th, 2007, 4:06pm
 
extrapixel wrote on Oct 24th, 2007, 3:58pm:
hi,

not sure if i understand... but isn't it just because we're working with pixels here, not vectors
Or else, post a code snippet demonstrating the problem you describe.


Yes i fill an PImage (80x80) with pixels and then use it as a texture which is then scaled 2.0

I expected to see rectangles, but i guess i need to set some special rendering bits somewhere...
Re: img scale artifacts
Reply #3 - Oct 24th, 2007, 4:27pm
 
ah, now I understand. Not sure about this across renderers... but this works as you expected at least in JAVA2D and smooth() turned off.

Click to turn smooth on/off:

Quote:


PImage img;
boolean smoothOn;

void setup() {
 size(200,200);
 img = createImage(80,80, RGB);
 for(int i=0; i < img.pixels.length; i++) {
   img.pixels[i] = color(random(255), random(255), random(255));
 }
 noSmooth();
 smoothOn = false;
}


void draw() {
 background(0);
 scale(20.0);
 image(img,0,0);
}

void mousePressed() {
 if (smoothOn) {
   noSmooth();
   smoothOn = false;
   println("smooth off");
 }
 else {
   smooth();
   smoothOn = true;
   println("smooth on");
 }
}


Re: img scale artifacts
Reply #4 - Oct 24th, 2007, 5:15pm
 
there is currently no way to make all the renderers do nearest neighbor filtering. sorry.
Re: img scale artifacts
Reply #5 - Oct 25th, 2007, 1:30am
 
Well, i've been having this same problem.
However i ask, isn't there a way to implement nearest neighbor?
well, i'm not exactly telling it to be done on a full aplication render, but at least on the PImage or PGraphics level.

I know next to nothing in graphics processing, but still this was suposed to be the easyest way to scale.

Maybe with OpenGL help or using OpenGL surfaces?
(that would also make it possible to implement resizeble application windows).

Once a teacher of mine was able to do a resizeble window, with nearest neighbor scaling using jogl. That particular piece of code was just a few lined after and before the render, with just the problem that the colors were all messed up (due to ARGB of OpenGL and not RPGA) and the image was also inverted. however i've lost that code since i had a problem with a hard-drive -_-!!. I'll try to ask him for the same effect.
Re: img scale artifacts
Reply #6 - Oct 25th, 2007, 12:20pm
 
[quote author=extrapixel]
Click to turn smooth on/off:
[/quote]

This works.
However is seems impossible to update the img in the draw() loop.
e.g. this gives a single static noise image, instead of a dyunamic one...

Code:

PImage img[] = {
createImage(80,80, RGB),
createImage(80,80, RGB),
createImage(80,80, RGB),
createImage(80,80, RGB)
};
boolean smoothOn;

void setup() {
size(800,800);
noSmooth();
smoothOn = false;

}


void draw() {
background(0);
for ( int k = 0; k < img.length; k++ ) {
loadPixels();
for(int i=0; i < img[k].pixels.length; i++) {
img[k].pixels[i] = color(random(255), random(255), random(255));
}
updatePixels();
}

scale(2.0);
int k = 0;
for ( int x = 0; x < 2; x++ ) {
for ( int y = 0; y < 2; y++ ) {
image(img[k++],x*80,y*80);
}
}
}

void mousePressed() {
if (smoothOn) {
noSmooth();
smoothOn = false;
println("smooth off");
}
else {
smooth();
smoothOn = true;
println("smooth on");
}
}

Re: img scale artifacts
Reply #7 - Oct 25th, 2007, 1:07pm
 
Try changeing your loadPixels() and updatePixels() to img[k].loadPixel() and img[k].updatePixels();
Re: img scale artifacts
Reply #8 - Oct 25th, 2007, 1:27pm
 
Quote:
Try changeing your loadPixels() and updatePixels() to img[k].loadPixel() and img[k].updatePixels();


YES!
thanks
Page Index Toggle Pages: 1