Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3055 Members - Latest Member: TipEpismKeype

11. February 2012, 01:18:34 PM
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)problem with creating mipmaps of grayscale texture (num components == 1)
Pages: [1]
Print
Author Topic: problem with creating mipmaps of grayscale texture (num components == 1)  (Read 279 times)
rwb1977
Enjoying the stay
*
Offline Offline

Posts: 45


View Profile
« on: 07. June 2010, 06:03:14 PM »

Seems to be a problem with this method in TextureFactory.java in jagatoo library.

In the case where pixelSize == 1, there are other format choices that it could be.

I've got an image that has the format TextureImageFormat.LUMINANCE, but this method gets called when creating mip maps, and the wrong texture format (TextureImageFormat.DEPTH) is chosen.

Code:
    /**
     * Creates an instance of {@link AbstractTextureImage} with an initialized
     * {@link ByteBuffer}, which is returned by the {@link AbstractTextureImage#getDataBuffer()} method.
     *
     * @param width
     * @param height
     * @param orgWidth
     * @param orgHeight
     * @param pixelSize
     *
     * @return the new AbstractTextureImage.
     */
    public final AbstractTextureImage createTextureImage( int width, int height, int orgWidth, int orgHeight, int pixelSize )
    {
        if ( pixelSize >= 8 )
            pixelSize /= 8;
       
        final TextureImageFormat format;
        switch ( pixelSize )
        {
            case 1:
                format = TextureImageFormat.DEPTH;
                break;
            case 2:
                format = TextureImageFormat.LUMINANCE_ALPHA;
                break;
            case 3:
                format = TextureImageFormat.RGB;
                break;
            case 4:
                format = TextureImageFormat.RGBA;
                break;
            default:
                throw new Error( "Unsupported pixel-size: " + pixelSize );
        }
       
        return ( createTextureImage( width, height, orgWidth, orgHeight, pixelSize, format ) );
    }

One thing I did to fix this was to change this line in PixelProcessor.java:
Code:
        AbstractTextureImage trgImg = texFactory.createTextureImage( trgWidth, trgHeight, trgWidth, trgHeight, pixelSize );

to:
Code:
        AbstractTextureImage trgImg = texFactory.createTextureImage( trgWidth, trgHeight, trgWidth, trgHeight, pixelSize, srcImg.getFormat() );
to avoid TextureImageFormat.DEPTH from being chosen, and instead passing the same format as the source image (TextureImageFormat.LUMINANCE).  However, there is still a general problem, I assume, when other places call this method.

I also had to fix the PixelProcessorLUM.java to handle the grayscale texture properly consistent with the PixelProcessorRGB):
Code:
Index: src/org/jagatoo/loaders/textures/pixelprocessing/PixelProcessorLUM.java
===================================================================
--- src/org/jagatoo/loaders/textures/pixelprocessing/PixelProcessorLUM.java (revision 378)
+++ src/org/jagatoo/loaders/textures/pixelprocessing/PixelProcessorLUM.java (working copy)
@@ -64,6 +64,9 @@
         Raster r = img.getRaster();
         
         final int trgOffset0 = trgOffset;
+       
+        final int trgLineSize = getLineSize( width );
+       
         trg.position( trgOffset0 );
         trg.limit( trg.capacity() );
         
@@ -81,7 +84,7 @@
                     trg.position( trgOffset );
                     trg.put( data, 0, width );
                     
-                    trgOffset += width;
+                    trgOffset += trgLineSize;
                 }
                 break;
             }
@@ -105,7 +108,7 @@
                         trg.put( trgOffsetX++, value );
                     }
                     
-                    trgOffset += width;
+                    trgOffset += trgLineSize;
                 }
                 break;
             }
@@ -133,12 +136,12 @@
                         trg.put( trgOffsetX++, value );
                     }
                     
-                    trgOffset += width;
+                    trgOffset += trgLineSize;
                 }
             }
         }
         
-        int dataSize = height * 1;
+        int dataSize = height * trgLineSize;
         
         trg.position( 0 );
         trg.limit( trgOffset0 + dataSize );

Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Online Online

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #1 on: 07. June 2010, 09:09:33 PM »

Please send me your sourceforce account name. I will grant you dev access.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic