Color table

Started by broumbroum, October 14, 2009, 23:26:05

Previous topic - Next topic

broumbroum

Hi ! Does anyone know where to find a short tutorial about Color Table lookup and openGL on the web ? I've read some into the opengl 2.0 official guide, which I barely managed to reimpl. in my app, but things are a bit messy.
I want to take control over the brightness and contrast of textures.

One big thing I'm wondering is how the ARBImaging is interpreted like by the graphics driver. Is ARB supported by the OGL software and/or OGL hardware ? e.g. glColorTable is using buffers (glbindbuffer() says "
            GL_PIXEL_PACK_BUFFER and GL_PIXEL_UNPACK_BUFFER are
            available only if the GL version is 2.1 or greater.
        ") are linked to the GL15 and GL21 class, and thus should that be ok to use buffers for average configurations ?


Evil-Devil

That looks cool. Thx for the link ^^ will see if there is some input in the opengl super bible too.

broumbroum

But still I'm having the color table as seen in the previous link from jogl, and using ARBImaging functions, the picture gets like inverted though I'm not inverting the table.
ByteBuffer tableData = ByteBuffer.allocate(256 * 3);
                                for (int i = 0; i < 256; i++) {
                                    byte b = (byte) i;/*((int) Math.max(0, Math.min(255, i * rescale + offset)));*/
                                    tableData.put(b);
                                    tableData.put(b);
                                    tableData.put(b);
                                }
                                tableData.rewind();
                                ARBImaging.glColorTable(ARBImaging.GL_COLOR_TABLE, GL11.GL_RGBA, 256, GL11.GL_RGB, GL11.GL_BYTE, tableData);
                                ARBImaging.glColorTableParameter(ARBImaging.GL_COLOR_TABLE, ARBImaging.GL_COLOR_TABLE_SCALE, FloatBuffer.wrap(new float[]{rescale, rescale, rescale, 1}));
                                ARBImaging.glColorTableParameter(ARBImaging.GL_COLOR_TABLE, ARBImaging.GL_COLOR_TABLE_BIAS, IntBuffer.wrap(new int[]{offset, offset, offset, 0}));
                               

then loading :
GL11.glBindTexture(Sf3Texture._EXTtex, name);
                                        ByteBuffer buffer = ByteBuffer.allocate(size.width * 4 * size.height);
                                        GL11.glEnable(ARBImaging.GL_COLOR_TABLE); // make color table enabled
                                        GL11.glGetTexImage(Sf3Texture._EXTtex, 0, GL11.GL_RGBA, GL11.GL_BYTE, buffer); // get a previously loaded 2D texture into a buffer
                                        GL11.glDisable(ARBImaging.GL_COLOR_TABLE);
                                        GL11.glBindTexture(Sf3Texture._EXTtex, 0);
                                        /** I'm using my impl of loading texture with the loaded buffer*/
Sf3Texture tex = GLHandler.newTexture(buffer, size, 4, Sf3Texture.TRANSFER_RGBA_TO_ABGR);
                                        int newName = initialized ? texNamesMap.get(key) : GLHandler._genVRAMFindVacant();
                                        GLHandler._GLLoadVRAM2D(tex, newName);
                                       

Picture is getting red.

broumbroum

/** I'm using my impl of loading texture with the loaded buffer*/
Sf3Texture tex = GLHandler.newTexture(buffer, size, GL11.GL_RGBA);
                                        int newName = initialized ? texNamesMap.get(key) : GLHandler._genVRAMFindVacant();
                                        GLHandler._GLLoadVRAM2D(tex, newName);

lookuptable (LUT) things are getting ok now... Since I'm tiling the picture I've got a messy code to debug because mappings to texture bindings are mixed up. :-\

broumbroum

Hi !
the JOGL sample is NOT useable with texture loading.
Read http://www.cs.utk.edu/~vose/c-stuff/opengl/glPixelTransfer.html
> the Pixel Transfer operation is indirectly effective on glteximage* if the GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE is enabled when GL_ARB_Imaging is available,
>  if no GL_ARB_Imaging, the pixeltransfer must be called directly by specifiying the GL_[color]_SCALE and GL_[color]_BIAS.
As a result, the code is changed like this :
                        /** build an identity with scale and bias LUT*/
                        ByteBuffer tableData = ByteBuffer.allocate(256 * 4);
                        for (int i = 0; i < 256; i++) {
                            byte b = (byte) Math.max(0f, Math.min(255f, i * rescale + offset));
                            tableData.put(b);
                            tableData.put(b);
                            tableData.put(b);
                            tableData.put((byte)i);
                        }
                        tableData.rewind();
                        /** parametrize with SCALE and BIAS */
                        /*GLHandler.ext._GLdisableEXT = true;*/
                        if (GLHandler.ext.ARBImaging.GL_isAvailable()) {
                            if (JXAenvUtils._debug) {
                                System.out.println("^^^^ ARBImaging available for colortable");
                            }
                            ARBImaging.glColorTable(ARBImaging.GL_POST_COLOR_MATRIX_COLOR_TABLE, GL11.GL_RGBA, 256, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, tableData);
                        } else {
                            if (JXAenvUtils._debug) {
                                System.out.println("^^^^ NO ARBImaging available for colortable");
                            }
                        }

  
 /** the texture is patched with LUT*/
                                GL11.glBindTexture(Sf3Texture._EXTtex, name);
                                ByteBuffer buffer = ByteBuffer.allocate(size.width * 4 * size.height);
                                GL11.glGetTexImage(Sf3Texture._EXTtex, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
                                /** save into the GL cache (made to VRAM available)*/
                                GL11.glBindTexture(Sf3Texture._EXTtex, 0);
                                Sf3Texture tex = GLHandler.newTexture(buffer, size, GL11.GL_RGBA);
                                int newName = initialized ? mTexNamesMap.get(key) : GLHandler._genVRAMFindVacant();
                                if (GLHandler.ext.ARBImaging.GL_isAvailable()) {
                                    GL11.glEnable(ARBImaging.GL_POST_COLOR_MATRIX_COLOR_TABLE);
                                } else {
                                    GL11.glPixelTransferf(GL11.GL_RED_SCALE, rescale);
                                    GL11.glPixelTransferf(GL11.GL_GREEN_SCALE, rescale);
                                    GL11.glPixelTransferf(GL11.GL_BLUE_SCALE, rescale);
                                    GL11.glPixelTransferf(GL11.GL_RED_BIAS, (float) offset / 256f);
                                    GL11.glPixelTransferf(GL11.GL_GREEN_BIAS, (float) offset / 256f);
                                    GL11.glPixelTransferf(GL11.GL_BLUE_BIAS, (float) offset / 256f);
                                }
                                newName = GLHandler._GLLoadVRAM2D(tex, newName);
                                if (GLHandler.ext.ARBImaging.GL_isAvailable()) {
                                    GL11.glDisable(ARBImaging.GL_POST_COLOR_MATRIX_COLOR_TABLE);
                                } else {
                                    GL11.glPixelTransferf(GL11.GL_RED_SCALE, 1f);
                                    GL11.glPixelTransferf(GL11.GL_GREEN_SCALE, 1f);
                                    GL11.glPixelTransferf(GL11.GL_BLUE_SCALE, 1f);
                                    GL11.glPixelTransferf(GL11.GL_RED_BIAS, 0f);
                                    GL11.glPixelTransferf(GL11.GL_GREEN_BIAS, 0f);
                                    GL11.glPixelTransferf(GL11.GL_BLUE_BIAS, 0f);
                                }
                                tex.destroyData();
                        

;D ;D
EDIT : another doc defines how glPixelTransfer and gl_arb_imaging are related http://linux.die.net/man/3/glpixeltransfer
EDIT : GL_POST_COLOR_MATRIX_COLOR_TABLE suits bests for loading texture with GL_ARB_imaging support.