private void readPixelFormat() throws IOException {
        int pfSize = in.readInt();
        if (pfSize != 32) {
            throw new IOException("Pixel format size is " + pfSize + ", not 32");
        }

        int pfFlags = in.readInt();
        is(pfFlags, DDPF_NORMAL);

        if (is(pfFlags, DDPF_FOURCC)) {
            compressed = true;
            int fourcc = in.readInt();
            int swizzle = in.readInt();
            in.skipBytes(16);

            switch (fourcc) {
                case PF_DXT1:
                    bpp = 4;
                    if (is(pfFlags, DDPF_ALPHAPIXELS)) {
                        pixelFormat = Image.Format.DXT1A;
                    } else {
                        pixelFormat = Image.Format.DXT1;
                    }
                    break;
                case PF_DXT3:
                    bpp = 8;
                    pixelFormat = Image.Format.DXT3;
                    break;
                case PF_DXT5:
                    bpp = 8;
                    pixelFormat = Image.Format.DXT5;
                    break;
                case PF_ATI1:
                    bpp = 4;
                    pixelFormat = Image.Format.RGTC1;
                    break;
                case PF_ATI2:
                    bpp = 8;
                    pixelFormat = Image.Format.RGTC2;
                    break;
                case PF_DX10:
                    compressed = false;
                    directx10 = true;
                    // exit here, the rest of the structure is not valid
                    // the real format will be available in the DX10 header
                    return;
                    
                case 113:
                    compressed = false;
                    bpp = 64;
                    pixelFormat = Image.Format.RGBA16F;
                    break;
                case 111:
                    compressed = false;
                    bpp = 16;
                    pixelFormat = Format.Luminance16F;
                    grayscaleOrAlpha = true;
                    break;
                case PF_BC4S:
                    bpp = 4;
                    pixelFormat = Format.SIGNED_RGTC1;
                    break;
                case PF_BC5S:
                    bpp = 8;
                    pixelFormat = Format.SIGNED_RGTC2;
                    break;
                case PF_ETC_RGB_CSN:
                    bpp = 4;
                    pixelFormat = Format.ETC1;
                    break;
                case PF_ETC2_RGB_CSN:
                    bpp = 4;
                    pixelFormat = Format.ETC1;
                    break;
                case PF_ETC2_RGBA1_CSN:
                    bpp = 4;
                    pixelFormat = Format.ETC2_ALPHA1;
                    break;
                case PF_ETC2_RGBA_CSN:
                    bpp = 8;
                    pixelFormat = Format.ETC2;
                    break;                                
                default:
                    throw new IOException("Unknown fourcc: " + string(fourcc) + ", " + Integer.toHexString(fourcc));
            }

            int size = ((width + 3) / 4) * ((height + 3) / 4) * bpp * 2;

            if (is(flags, DDSD_LINEARSIZE)) {
                if (pitchOrSize == 0) {
                    logger.warning("Must use linear size with fourcc");
                    pitchOrSize = size;
                } else if (pitchOrSize != size) {
                    logger.log(Level.WARNING, "Expected size = {0}, real = {1}",
                            new Object[]{size, pitchOrSize});
                }
            } else {
                pitchOrSize = size;
            }
        } else {
            compressed = false;

            // skip fourCC
            in.readInt();

            bpp = in.readInt();
            redMask = in.readInt();
            greenMask = in.readInt();
            blueMask = in.readInt();
            alphaMask = in.readInt();

            if (is(pfFlags, DDPF_RGB)) {
                if (is(pfFlags, DDPF_ALPHAPIXELS)) {
                    if (bpp == 16) {
                        pixelFormat = Format.RGB5A1;
                    } else {
                        pixelFormat = Format.RGBA8;
                    }
                } else {
                    if (bpp == 16) {
                        pixelFormat = Format.RGB565;
                    } else {
                        pixelFormat = Format.RGB8;
                    }
                }
            } else if (is(pfFlags, DDPF_GRAYSCALE) && is(pfFlags, DDPF_ALPHAPIXELS)) {
                switch (bpp) {
                    case 16:
                        pixelFormat = Format.Luminance8Alpha8;
                        break;
                    default:
                        throw new IOException("Unsupported GrayscaleAlpha BPP: " + bpp);
                }
                grayscaleOrAlpha = true;
            } else if (is(pfFlags, DDPF_GRAYSCALE)) {
                switch (bpp) {
                    case 8:
                        pixelFormat = Format.Luminance8;
                        break;
                    default:
                        throw new IOException("Unsupported Grayscale BPP: " + bpp);
                }
                grayscaleOrAlpha = true;
            } else if (is(pfFlags, DDPF_ALPHA)) {
                switch (bpp) {
                    case 8:
                        pixelFormat = Format.Alpha8;
                        break;
                    default:
                        throw new IOException("Unsupported Alpha BPP: " + bpp);
                }
                grayscaleOrAlpha = true;
            } else {
                throw new IOException("Unknown PixelFormat in DDS file");
            }

            int size = (bpp / 8 * width);

            if (is(flags, DDSD_LINEARSIZE)) {
                if (pitchOrSize == 0) {
                    logger.warning("Linear size said to contain valid value but does not");
                    pitchOrSize = size;
                } else if (pitchOrSize != size) {
                    logger.log(Level.WARNING, "Expected size = {0}, real = {1}",
                            new Object[]{size, pitchOrSize});
                }
            } else {
                pitchOrSize = size;
            }
        }
    }
Reads the PixelFormat structure in a DDS file
jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java