예제 #1
0
 /**
  * @param ddsImage
  * @param mipNumber
  * @param imageName
  */
 public DDSDecompressor(DDSImage ddsImage, int mipNumber, String imageName) {
   this.imageName = imageName;
   this.ddsImage = ddsImage;
   this.mipNumber = mipNumber;
   this.imageInfo = ddsImage.getAllMipMaps()[mipNumber];
   this.width = imageInfo.getWidth();
   this.height = imageInfo.getHeight();
   this.buffer = imageInfo.getData();
 }
예제 #2
0
  /** @return a new non-cached {@code BufferedImage} */
  public BufferedImage convertImage() {

    // can't use width or height as it's been corrected to 1 already
    if (imageInfo.getWidth() < 1 || imageInfo.getHeight() < 1) {
      return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    }

    // prep the buffer
    buffer.rewind();
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_DXT1) {
      // System.out.println("DXT1");
      if (!ddsImage.isPixelFormatFlagSet(DDSImage.DDPF_ALPHAPIXELS)) {
        // TODO: how do I discover no alpha flag?
        // C:\game media\Black Prophecy\Textures\avatar_ai_pilot_f3_05.dds wants no alpha flag
        // possibly no mips maps indicates this?
        return decodeDxt1Buffer();
      } else {
        System.out.println("Alpha present in DXT1!; mip num = " + mipNumber);
        // return decompressRGBA_S3TC_DXT1_EXT(ddsImage.getMipMap(mipNumber));
      }
    } else if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_DXT3) {
      return decodeDxt3Buffer();
    } else if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_DXT5) {
      return decompressRGBA_S3TC_DXT5_EXT();
    } else if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_ATI2) {
      // NOT correct but it gives you the idea a bit
      return decompressRGBA_S3TC_DXT5_EXT();
    } else if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_R8G8B8) {
      return decodeR8G8B8();
    } else if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_A8R8G8B8) {
      return decodeA8R8G8B8();
    } else if (ddsImage.getPixelFormat() == DDSImage.D3DFMT_X8R8G8B8) {
      return decodeA8R8G8B8();
    } else if (ddsImage.getPixelFormat() == DDSImage.DDS_A16B16G16R16F) {
      return decodeA16R16G16B16();
    }
    System.err.println("BAD DXT format!! " + ddsImage.getPixelFormat());
    return null;
  }