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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › upscaling images with/without opengl
Page Index Toggle Pages: 1
upscaling images with/without opengl (Read 860 times)
upscaling images with/without opengl
Feb 28th, 2006, 4:27pm
 

First of all, great software! Great also for looping trough individual pixels, which is extremely cpu intensive (read: impossible) with actionscript. I noticed the bug about the pixel operations (pixel[]/set()/get()) that have been broken for opengl in the beta-release. Fixing this is said to have a low priority since pixel operations did not benefit from the opengl renderer. I receive 160-120 matrixes from eyesweb via a socket connection, and want to upscale them to 800-600 (image(0,0,800,600)). The upscaling alone takes about 80 % of my cpu (amd athlon 2800) without opengl, and almost nothing with opengl hardware acceleration. The problem is that I can't make the matrix into an image without using pixels[]. Does anyone know another way for getting fullscreen images, or will there be a fix in the near future?
Regards, holst
Re: upscaling images with/without opengl
Reply #1 - Feb 28th, 2006, 4:55pm
 
Making a 160x120 PImage and updating it using pixels should work with OPENGL. If you create the PImage in setup() and update it in draw() it should work pretty quickly.  

I don't know about eyesweb sockets but depending on how often you receive data from there and how that code works, you might not want to convert from a matrix to an image every frame.

Here's an example:

Code:


import processing.opengl.*;

// global image for reuse in draw
PImage img;

void setup() {

size(800,600,OPENGL);

// initialise image once only
img = new PImage(160,120);

// for this example, use HSB not RGB...
colorMode(HSB);
}

void draw() {

background(0);

// loop through all pixels in img
img.loadPixels();
for (int i = 0; i < img.pixels.length; i++) {
// work out x and y of pixels[i]
float x = i%img.width;
float y = i/img.width;
// work out angle from mouse to screen location of pixels[i]
float ang = atan2(y-(img.height*mouseY/height),x-(img.width*mouseX/width));
// colour pixels[i] according to angle
img.pixels[i] = color(255*(ang+PI)/TWO_PI,255,255);
}
img.updatePixels();

// draw img full screen
image(img,0,0,width,height);

}


Re: upscaling images with/without opengl
Reply #2 - Feb 28th, 2006, 6:12pm
 
Thnx TomC,
your example works. I got confused because pixels[] seems to work with P3D and not with OPENGL, and img.pixels[] seems to work with both. (is that correct?) Also, with P3D I do not need to call img.loadPixels[] and img.updatePixels[] before calling image(img,0,0,800,600), and with OPENGL I do. (also correct?) I forgot to change that when switching render mode.
Re: upscaling images with/without opengl
Reply #3 - Feb 28th, 2006, 6:43pm
 
Yes, that's right on both counts as I understand it.  The bug (91) is with pixels, copy, get() and set() for the main applet.  It should be OK with images if you remember to do load and updatePixels.
Page Index Toggle Pages: 1