Search in sources :

Example 6 with TextureDefinition

use of net.runelite.cache.definitions.TextureDefinition in project runelite by runelite.

the class TextureDumper method extract.

@Test
public void extract() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(base)) {
        store.load();
        TextureManager tm = new TextureManager(store);
        tm.load();
        for (TextureDefinition texture : tm.getTextures()) {
            Files.write(gson.toJson(texture), new File(outDir, texture.getId() + ".json"), Charset.defaultCharset());
            ++count;
        }
    }
    logger.info("Dumped {} textures to {}", count, outDir);
}
Also used : Store(net.runelite.cache.fs.Store) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) File(java.io.File) Test(org.junit.Test)

Example 7 with TextureDefinition

use of net.runelite.cache.definitions.TextureDefinition in project runelite by runelite.

the class ModelViewer method getTexture.

private static Texture getTexture(int id) {
    Texture texture = textures.get(id);
    if (texture != null) {
        return texture;
    }
    TextureDefinition td;
    try (FileInputStream fin = new FileInputStream("textures/" + id + ".json")) {
        td = new Gson().fromJson(new InputStreamReader(fin), TextureDefinition.class);
    } catch (IOException ex) {
        logger.warn(null, ex);
        return null;
    }
    try (FileInputStream fin = new FileInputStream("sprite/" + td.getFileIds()[0] + "-0.png")) {
        BufferedImage image = ImageIO.read(fin);
        int width = image.getWidth();
        int height = image.getHeight();
        int[] rgb = new int[width * height];
        int[] out = image.getRGB(0, 0, width, height, rgb, 0, width);
        assert rgb == out;
        ByteBuffer buffer = ByteBuffer.allocateDirect(rgb.length * 4);
        for (int i = 0; i < rgb.length; ++i) {
            int pixel = rgb[i];
            // argb -> rgba
            int a = pixel >>> 24;
            int r = (pixel >> 16) & 0xff;
            int g = (pixel >> 8) & 0xff;
            int b = pixel & 0xff;
            buffer.put((byte) r);
            buffer.put((byte) g);
            buffer.put((byte) b);
            buffer.put((byte) a);
        }
        buffer.position(0);
        int glTexture = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTexture);
        // Setup filtering, i.e. how OpenGL will interpolate the pixels when scaling up or down
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        // Setup wrap mode, i.e. how OpenGL will handle pixels outside of the expected range
        // Note: GL_CLAMP_TO_EDGE is part of GL12
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
        // Linear Filtering
        GL11.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        // Linear Filtering
        GL11.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        texture = new Texture(rgb, width, height, glTexture);
        textures.put(id, texture);
        return texture;
    } catch (IOException ex) {
        logger.warn(null, ex);
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage)

Aggregations

TextureDefinition (net.runelite.cache.definitions.TextureDefinition)7 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 TextureLoader (net.runelite.cache.definitions.loaders.TextureLoader)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 FSFile (net.runelite.cache.fs.FSFile)2 Gson (com.google.gson.Gson)1 Color (java.awt.Color)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)1 SpriteDefinition (net.runelite.cache.definitions.SpriteDefinition)1 ModelLoader (net.runelite.cache.definitions.loaders.ModelLoader)1 SpriteLoader (net.runelite.cache.definitions.loaders.SpriteLoader)1 ItemProvider (net.runelite.cache.definitions.providers.ItemProvider)1