Loading...
Logo
Processing Forum
Hi.
I have a sketch which loads images into PImage.
I would like to use P3D mode to use blending shaders.
My problem is:
in P3D, the screen freezes while the loading thread is running.
It works fine without P3D…

How could I avoid this problem ? Is that something to do with the OPENGL thread ?

here's the code to demonstrate the problem:
  1. PImage images[] = new PImage[9];
  2. final int loadedI = 3;//number of images to load
  3. final int IMAGE_WIDTH= 1280; //width of loaded images
  4. final int IMAGE_HEIGHT= 800; //height of loaded images
  5. int h;
  6. void setup()
  7. {
  8.   size(1280, 800, P3D); //SWITCH P3D ON AND OFF TO SEE THE OPENGL BLOCKS THE LOADING THREAD
  9.   background(0);
  10.   for (int i = 0; i < images.length; i++)
  11.   {
  12.     images[i] = new PImage(IMAGE_WIDTH, IMAGE_HEIGHT, RGB);
  13.   }
  14. }
  15. void draw()
  16. {
  17.   background(0);
  18.   println(frameRate);
  19.   for (int t = 0; t <loadedI; t++)
  20.   {
  21.     image(images[t], t*width/loadedI, height/2, width/loadedI, width/loadedI);
  22.   }
  23.   ellipse();//TO VISUALISE THE "INTERRUPTION OF THE SCREEN"
  24. }
  25. void ellipse()
  26. {
  27.   h++;
  28.   if (h>height) h=0;
  29.   fill(255);
  30.   ellipse(width/2, h, 50, 50);
  31. }
  32. void mousePressed()
  33. {
  34.   for (int i= 0; i<loadedI; i++) {
  35.     (new ImageLoaderThread(this, i, i )).start();
  36.   }
  37. }
and here's the thread:
Copy code
  1. class ImageLoaderThread extends Thread
    {

      private PApplet pa;
      private String fileName;
      private int gridIndex;
      public ImageLoaderThread(PApplet pa, int imageIndex, int gridIndex)
      {
        this.pa = pa;
        fileName = imageIndex+".jpg";
        this.gridIndex = gridIndex;
      }

      public void run()
      {
        images[gridIndex] = loadImage(fileName);
        images[gridIndex].updatePixels();

        images[gridIndex].pixels = null;
      }
    }

Replies(4)

@ PImage reference ->  http://processing.org/reference/PImage.html
there's a warning:
To create a new image, use the  createImage()  function. Do not use the syntax  new PImage() .
Perhaps that's the problem? Some classes need specialized instantiation rather than a direct  new!   
Of course, there's an internal new issued by createImage() function!   
thanks but it doesn't change anything

The heap size of PImage in P3D is greater than in A2D… for 3 images: 92 mo in A2D and 149 mo in P3D.
This could be the cause of the freeze.

for instance…How could I sent to processing (thanks openglES library) a compressed opengl texture and manage it directly from my shader into processing?
Do I have to use PImage ? I think using PImage could be the cause of the memory increasing which may cause the freeze of the screen…

Hi again !
I edited the tittle of the topic according to my researches.
I would like to implement texture compression in processing/android. (like ETC, PVRTC…).
As this video shows: you reduce (about 5 TIMES !!!! ) the memory allocated to your image in OPENGL ! It would be very nice to have a processing solution for implementation ! I think it could interest the community, am I wrong ?

I'm trying to implement it in processing, with no results so far to post.
Maybe some of you have already tried to work around this ! Any advices, points of view would be appreciated !
What would be the way to processing take advantage of the power of openglES2 ?

Tiouus !!
ok- I'm pretty stuck right now;

here's where I am:
you can download JPEG TEXTURE here, and compressed texture here. You can use THIS tool to make your own compression.
here's the code I have so far:  I don't know the way to call loadtexture() method…So nothing occurs.

The code is supposed to load the .pkm compressed texture if your android device can handle ETC1 functions, if not, it will download the regular JPEG texture.
Any help would be very appreciated ! thanks.
Copy code
  1. import android.opengl.ETC1Util;
    import android.content.Context;
    import java.nio.Buffer;
    import java.nio.ByteBuffer;
    import java.nio.ByteOrder;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.nio.ShortBuffer;
    import java.util.Arrays;
    import java.io.InputStream;
    import processing.core.PApplet;
    import processing.opengl.tess.PGLU;
    import processing.opengl.tess.PGLUtessellator;
    import processing.opengl.tess.PGLUtessellatorCallbackAdapter;
    import javax.microedition.khronos.egl.EGL10;
    import javax.microedition.khronos.egl.EGLConfig;
    import javax.microedition.khronos.egl.EGLContext;
    import javax.microedition.khronos.egl.EGLDisplay;
    import javax.microedition.khronos.opengles.*;
    import android.util.Log;
    import android.opengl.GLES20;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.opengl.GLSurfaceView.EGLConfigChooser;
    import android.opengl.GLSurfaceView.Renderer;
    import android.opengl.GLSurfaceView;
    import android.opengl.GLU;
    import android.opengl.GLUtils;
    Context context;
    Bitmap bitmap;
    int textureIDs[];
    private static final String TAG = "MyActivity";
    PGraphics3D pg = (PGraphics3D) g;

    void setup()
    {
      size(2560, 1600, P3D);
      background(90);
      println("try to display an ETC1 compressed texture on Android/Processing");
      println(pg.OPENGL_VENDOR);
      println(pg.OPENGL_RENDERER);
      println(pg.OPENGL_VERSION);
      println(pg.OPENGL_EXTENSIONS);
      println(pg.maxLineWidth);
      println(pg.maxPointSize);
      println("Max texture size: "+ pg.maxTextureSize);
    }

    void draw()
    {
    }

    void mousePressed()
    {
    }

    // Load an image into GL texture
    public void loadTexture(GL10 gl) throws java.io.IOException {

      Boolean loadCompressed = true;
      if (loadCompressed) {
        /****************************************************/
        /** LOAD A COMPRESSED TEXTURE IMAGE */
        /***********************************/
        println( ": ETC1 texture support: " + ETC1Util.isETC1Supported());
        try {
          ETC1Util.loadTexture(GLES20 .GL_TEXTURE_2D, 0, 0,
          GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5,
          getApplicationContext().openFileInput("texture.pkm"));

          Log.w(TAG, ": OpenGL Error -After LoadTexture()-:" + gl.glGetError());
          Log.w(TAG, "OpenGL Extensions: " + gl.glGetString(GL10.GL_EXTENSIONS));
        }
        catch (IOException e) {
          Log.w(TAG, ": Could not load texture: " + e);
        }
        finally {

          Log.w(TAG, ": OpenGL Error -In Final()-:" + gl.glGetError());
        }
      }
      else {
        /*****************************************************/
        /** LOAD A TEXTURE IMAGE */
        /************************/

        gl.glGenTextures(1, textureIDs, 0); // Generate texture-ID array
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[0]); // Bind to texture ID Set up texture filters
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
        InputStream istream= getApplicationContext().openFileInput("texture.jpg");

        try {
          bitmap = BitmapFactory.decodeStream(istream);
        }
        finally {
          try {
            istream.close();
          }
          catch (IOException e) {
          }
        }
        // Build Texture from loaded bitmap for the currently-bind texture
        // ID
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();
        /******************************************************/
      }
    }