package me.hugmanrique.pokedata.utils;

import me.hugmanrique.pokedata.compression.Lz77;
import me.hugmanrique.pokedata.graphics.ImageType;
import me.hugmanrique.pokedata.graphics.Palette;
import me.hugmanrique.pokedata.graphics.ROMImage;
import me.hugmanrique.pokedata.roms.ROM;

/**
 * @author Hugmanrique
 * @since 01/06/2017
 */
public class ImageUtils {
    public static Palette getPalette(ROM rom, int pointer, ImageType type) {
        int[] data = Lz77.decompress(rom, pointer);

        return new Palette(type, data);
    }

    public static Palette getPalette(ROM rom, int pointer) {
        return getPalette(rom, pointer, ImageType.C16);
    }

    public static ROMImage getImage(ROM rom, int pointer, Palette palette, int width, int height) {
        int[] data = Lz77.decompress(rom, pointer);

        return new ROMImage(palette, data, width, height);
    }
}

@@ -278,162 +278,606 @@
 M;%0A%0A
-/**%0A * @author Hugmanrique%0A * @since 01/06/2017%0A */%0Apublic class ImageUtils %7B%0A    public static Palette getPalette(ROM rom, int pointer, ImageType type) %7B
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * %7B@link Palette%7D and %7B@link ROMImage%7D loader that keeps a palette cache to%0A * avoid too many %7B@link me.hugmanrique.pokedata.compression.HexInputStream%7D creation to decompress Lz77%0A * @author Hugmanrique%0A * @since 01/06/2017%0A * @see Palette%0A * @see ROMImage%0A */%0Apublic class ImageUtils %7B%0A    private static Map%3CInteger, Palette%3E paletteCache = new HashMap%3C%3E();%0A%0A    public static Palette getPalette(ROM rom, int pointer, ImageType type) %7B%0A        if (paletteCache.containsKey(pointer)) %7B%0A            return paletteCache.get(pointer);%0A        %7D%0A
 %0A   
@@ -930,30 +930,41 @@
 );%0A%0A        
-return
+Palette palette =
  new Palette
@@ -977,16 +977,85 @@
  data);%0A
+        paletteCache.put(pointer, palette);%0A%0A        return palette;%0A
     %7D%0A%0A 

Create Palette cache in ImageUtils