Пример #1
0
  private void convertFromBgr2RGBA(TpcMipMap mipMap) {
    byte[] src = mipMap.getData();
    byte[] dest = new byte[mipMap.getWidth() * mipMap.getHeight() * 4];
    int destIndex = 0;
    for (int i = 0; i < dest.length; i += 3, destIndex += 4) {
      dest[destIndex + 0] = src[i + 2];
      dest[destIndex + 1] = src[i + 1];
      dest[destIndex + 2] = src[i + 0];
      dest[destIndex + 3] = -1;
    }

    mipMap.setData(dest);
    mipMap.setSize(dest.length);
    verticalMirror(mipMap, 4);
  }
Пример #2
0
  public static void verticalMirror(TpcMipMap mipMap, int recordSize) {
    byte[] dest = mipMap.getData();
    int halfOfHeight = mipMap.getHeight() / 2;
    int pitch = mipMap.getWidth() * recordSize;
    for (int j = 0; j < halfOfHeight; j++) {
      int index1 = j * pitch;
      int index2 = (mipMap.getHeight() - j - 1) * pitch;
      for (int i = 0; i < pitch; i++, index1++, index2++) {

        byte t = dest[index1];
        dest[index1] = dest[index2];
        dest[index2] = t;
      }
    }
  }
Пример #3
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);
  }