Search in sources :

Example 1 with TextureLoader

use of net.runelite.cache.definitions.loaders.TextureLoader in project runelite by runelite.

the class TextureManager method load.

public void load() throws IOException {
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.TEXTURES);
    Archive archive = index.getArchive(0);
    byte[] archiveData = storage.loadArchive(archive);
    ArchiveFiles files = archive.getFiles(archiveData);
    TextureLoader loader = new TextureLoader();
    for (FSFile file : files.getFiles()) {
        TextureDefinition texture = loader.load(file.getFileId(), file.getContents());
        textures.add(texture);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) Index(net.runelite.cache.fs.Index) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) FSFile(net.runelite.cache.fs.FSFile)

Example 2 with TextureLoader

use of net.runelite.cache.definitions.loaders.TextureLoader in project runelite by runelite.

the class CacheController method getItemImage.

@RequestMapping(path = "item/{itemId}/image", produces = "image/png")
public ResponseEntity<byte[]> getItemImage(@PathVariable int itemId, @RequestParam(defaultValue = "1") int quantity, @RequestParam(defaultValue = "1") int border, @RequestParam(defaultValue = "3153952") int shadowColor) throws IOException {
    final CacheEntry cache = cacheService.findMostRecent();
    ItemProvider itemProvider = new ItemProvider() {

        @Override
        public ItemDefinition provide(int itemId) {
            try {
                return getItem(itemId);
            } catch (IOException ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    ModelProvider modelProvider = new ModelProvider() {

        @Override
        public ModelDefinition provide(int modelId) throws IOException {
            IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.MODELS.getNumber());
            ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, modelId);
            byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data;
            return new ModelLoader().load(modelId, archiveData);
        }
    };
    SpriteProvider spriteProvider = new SpriteProvider() {

        @Override
        public SpriteDefinition provide(int spriteId, int frameId) {
            try {
                IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.SPRITES.getNumber());
                ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, spriteId);
                byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data;
                SpriteDefinition[] defs = new SpriteLoader().load(spriteId, archiveData);
                return defs[frameId];
            } catch (Exception ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    TextureProvider textureProvider2 = new TextureProvider() {

        @Override
        public TextureDefinition[] provide() {
            try {
                IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.TEXTURES.getNumber());
                ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, 0);
                ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry);
                TextureLoader loader = new TextureLoader();
                TextureDefinition[] defs = new TextureDefinition[archiveFiles.getFiles().size()];
                int i = 0;
                for (FSFile file : archiveFiles.getFiles()) {
                    TextureDefinition def = loader.load(file.getFileId(), file.getContents());
                    defs[i++] = def;
                }
                return defs;
            } catch (Exception ex) {
                log.warn(null, ex);
                return null;
            }
        }
    };
    BufferedImage itemImage = ItemSpriteFactory.createSprite(itemProvider, modelProvider, spriteProvider, textureProvider2, itemId, quantity, border, shadowColor, false);
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    ImageIO.write(itemImage, "png", bao);
    return ResponseEntity.ok(bao.toByteArray());
}
Also used : ItemProvider(net.runelite.cache.definitions.providers.ItemProvider) TextureLoader(net.runelite.cache.definitions.loaders.TextureLoader) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition) IndexEntry(net.runelite.http.service.cache.beans.IndexEntry) ArchiveEntry(net.runelite.http.service.cache.beans.ArchiveEntry) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) TextureProvider(net.runelite.cache.definitions.providers.TextureProvider) IOException(java.io.IOException) NotFoundException(net.runelite.http.service.util.exception.NotFoundException) BufferedImage(java.awt.image.BufferedImage) FSFile(net.runelite.cache.fs.FSFile) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) SpriteLoader(net.runelite.cache.definitions.loaders.SpriteLoader) SpriteProvider(net.runelite.cache.definitions.providers.SpriteProvider) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TextureDefinition (net.runelite.cache.definitions.TextureDefinition)2 TextureLoader (net.runelite.cache.definitions.loaders.TextureLoader)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 FSFile (net.runelite.cache.fs.FSFile)2 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)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 ModelProvider (net.runelite.cache.definitions.providers.ModelProvider)1 SpriteProvider (net.runelite.cache.definitions.providers.SpriteProvider)1 TextureProvider (net.runelite.cache.definitions.providers.TextureProvider)1 Archive (net.runelite.cache.fs.Archive)1 Index (net.runelite.cache.fs.Index)1 Storage (net.runelite.cache.fs.Storage)1 ArchiveEntry (net.runelite.http.service.cache.beans.ArchiveEntry)1 CacheEntry (net.runelite.http.service.cache.beans.CacheEntry)1 IndexEntry (net.runelite.http.service.cache.beans.IndexEntry)1