Ejemplo n.º 1
0
  public void convert2RGBA(TpcTexture texture) {
    if (texture.isCompressed()) {
      return;
    }

    for (TpcMipMap mipMap : texture.getMipMaps()) {
      if (texture.getFormat() == TpcPixelFormat.RGB) {
        convertFromRGB2RGBA(mipMap);
        texture.setDataType(PixelDataType.PixelDataType8);
        texture.setFormat(TpcPixelFormat.RGBA);
        texture.setRawFormat(TpcPixelFormatRaw.RGBA8);
        texture.setMinDataSize(4);
      } else if (texture.getFormat() == TpcPixelFormat.BGR) {
        convertFromBgr2RGBA(mipMap);
        texture.setDataType(PixelDataType.PixelDataType8);
        texture.setFormat(TpcPixelFormat.RGBA);
        texture.setRawFormat(TpcPixelFormatRaw.RGBA8);
        texture.setMinDataSize(4);
      } else if (texture.getFormat() == TpcPixelFormat.GRAY) {
        convertFromGRAY2RGBA(mipMap);
        texture.setDataType(PixelDataType.PixelDataType8);
        texture.setFormat(TpcPixelFormat.RGBA);
        texture.setRawFormat(TpcPixelFormatRaw.RGBA8);
        texture.setMinDataSize(4);
      }
    }
  }
Ejemplo n.º 2
0
  public void decompress(TpcTexture texture) throws IOException {
    if (!texture.isCompressed()) {
      return;
    }
    if (!(texture.getRawFormat() == TpcPixelFormatRaw.DXT1
        || texture.getRawFormat() == TpcPixelFormatRaw.DXT3
        || texture.getRawFormat() == TpcPixelFormatRaw.DXT5)) {
      throw new IllegalArgumentException(
          "Bad compression format "
              + texture.getRawFormat()
              + " in texture ["
              + texture.getName()
              + "]");
    }

    for (TpcMipMap mipMap : texture.getMipMaps()) {
      ByteArrayInputStream src =
          new ByteArrayInputStream(Arrays.copyOf(mipMap.getData(), mipMap.getData().length));
      /* The DXT algorithms work on 4x4 pixel blocks. Textures smaller than one
       * block will be padded, but larger textures need to be correctly aligned. */
      byte[] result;
      if (texture.getRawFormat() == TpcPixelFormatRaw.DXT1) {
        result = decompressDxt1(texture, src);
        mipMap.setData(result);
        mipMap.setSize(mipMap.getWidth() * mipMap.getHeight() * 4);
      } else if (texture.getRawFormat() == TpcPixelFormatRaw.DXT5) {
        result = decompressDxt5(texture, src);
        mipMap.setData(result);
        mipMap.setSize(mipMap.getWidth() * mipMap.getHeight() * 4);
        verticalMirror(mipMap, 4);
      } else if (texture.getRawFormat() == TpcPixelFormatRaw.DXT3) {
        throw new RuntimeException("DXT3 uncompression is not implemented yet");
      } else {
        throw new RuntimeException("Unknown compression");
      }
    }

    texture.setCompressed(false);
    texture.setDataType(PixelDataType.PixelDataType8);
    texture.setFormat(TpcPixelFormat.RGBA);
    texture.setRawFormat(TpcPixelFormatRaw.RGBA8);
    texture.setMinDataSize(4);
  }