// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public class SIFConfig {
// 	private static final Logger logger = LoggerFactory
// 			.getLogger(SIFConfig.class);
// 
// 	public static SIFConfig instance;
// 	private String filePath = "sif.xml";
// 	private Map<String, String> conf = Collections
// 			.synchronizedMap(new HashMap<String, String>());
// 
// 	public static SIFConfig getInstance() {
// 		if (instance == null) {
// 			instance = new SIFConfig();
// 		}
// 		return instance;
// 	}
// 
// 	private SIFConfig() {
// 	}
// 
// 	public void loadConfig() throws DocumentException {
// 		if(!new File(filePath).exists()) {
// 			logger.info("Could not find sif.xml.");
// 			return;
// 		}
// 		logger.info("Read config file sif.xml");
// 		SAXReader reader = new SAXReader();
// 		Document doc = reader.read(new File(filePath));
// 		List nodes = doc.getRootElement().elements("config");
// 		for (Iterator it = nodes.iterator(); it.hasNext();) {
// 			Element elm = (Element) it.next();
// 			String name = elm.attributeValue("name");
// 			String value = elm.attributeValue("value");
// 			if (name != null && value != null) {
// 				conf.put(name, value);
// 				logger.info("Read conf: {}={}", name, value);
// 			}
// 		}
// 	}
// 
// 	public void saveConfig() throws IOException {
// 		logger.info("Save config file sif.xml");
// 		Document doc = DocumentHelper.createDocument();
// 		Element root = DocumentHelper.createElement("configuration");
// 		for (String name : conf.keySet()) {
// 			String value = "" + conf.get(name);
// 			Element conf = DocumentHelper.createElement("config");
// 			conf.addAttribute(new QName("name"), name);
// 			conf.addAttribute(new QName("value"), value);
// 			root.add(conf);
// 		}
// 		doc.setRootElement(root);
// 
// 		OutputFormat format = OutputFormat.createPrettyPrint();
// 		format.setEncoding("UTF-8"); // 指定XML编码
// 		XMLWriter writer = new XMLWriter(new FileWriter(filePath), format);
// 		writer.write(doc);
// 		writer.close();
// 	}
// 
// 	public String get(String name) {
// 		return conf.get(name);
// 	}
// 
// 	public String set(String name, String value) {
// 		return conf.put(name, value);
// 	}
// 
// 	public static class ConfigName {
// 		public static final String dbPath = "dbPath";
// 		public static final String assetsPath = "assetsPath";
// 	}
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public static class ConfigName {
// 	public static final String dbPath = "dbPath";
// 	public static final String assetsPath = "assetsPath";
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/data/ImagDao.java
// public interface ImagDao {
// 	public BufferedImage getImage(String imagPath) throws IOException;
// 	
// 	public BufferedImage getImageWithoutSplit(String texbPath) throws IOException;
// 	
// 	public String getRefTextureFilePath(String imagPath) throws IOException;
// 	
// 	public List<String> getImagList();
// 	
// 	public List<String> getTexbList();
// }


import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.Inflater;
import javax.imageio.ImageIO;
import me.xwang1024.sifResExplorer.config.SIFConfig;
import me.xwang1024.sifResExplorer.config.SIFConfig.ConfigName;
import me.xwang1024.sifResExplorer.data.ImagDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

		BufferedImage cache = null;
		for (Timg img : texture.image) {
			long x1 = img.vertices[0].u;
			long y1 = img.vertices[0].v;
			long x2 = img.vertices[img.vertexLen - 1].u;
			long y2 = img.vertices[img.vertexLen - 1].v;
			BufferedImage bimg = image.getSubimage((int) x1, (int) y1, (int) (x2 - x1),
					(int) (y2 - y1));
			String pngPath = img.path.replaceAll("\\.imag.*$", "");
			File pngFile = new File(tempDir, pngPath);
			System.out.println(pngFile.getAbsolutePath());
			pngFile.getParentFile().mkdirs();
			try {
				ImageIO.write(bimg, "png", pngFile);
			} catch (IOException e) {
				logger.error("{} temp file write error.", pngFile.getAbsolutePath());
				e.printStackTrace();
				continue;
			}
			if (img.path.contains(this.imagPath)) {
				cache = bimg;
			} else {
				logger.debug("{}:{}", img.path, this.imagPath);
			}
		}
		return cache;
	}

	private Texb extractTexb(String texbPath) throws IOException {
		// 构造texb文件的位置

// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public class SIFConfig {
// 	private static final Logger logger = LoggerFactory
// 			.getLogger(SIFConfig.class);
// 
// 	public static SIFConfig instance;
// 	private String filePath = "sif.xml";
// 	private Map<String, String> conf = Collections
// 			.synchronizedMap(new HashMap<String, String>());
// 
// 	public static SIFConfig getInstance() {
// 		if (instance == null) {
// 			instance = new SIFConfig();
// 		}
// 		return instance;
// 	}
// 
// 	private SIFConfig() {
// 	}
// 
// 	public void loadConfig() throws DocumentException {
// 		if(!new File(filePath).exists()) {
// 			logger.info("Could not find sif.xml.");
// 			return;
// 		}
// 		logger.info("Read config file sif.xml");
// 		SAXReader reader = new SAXReader();
// 		Document doc = reader.read(new File(filePath));
// 		List nodes = doc.getRootElement().elements("config");
// 		for (Iterator it = nodes.iterator(); it.hasNext();) {
// 			Element elm = (Element) it.next();
// 			String name = elm.attributeValue("name");
// 			String value = elm.attributeValue("value");
// 			if (name != null && value != null) {
// 				conf.put(name, value);
// 				logger.info("Read conf: {}={}", name, value);
// 			}
// 		}
// 	}
// 
// 	public void saveConfig() throws IOException {
// 		logger.info("Save config file sif.xml");
// 		Document doc = DocumentHelper.createDocument();
// 		Element root = DocumentHelper.createElement("configuration");
// 		for (String name : conf.keySet()) {
// 			String value = "" + conf.get(name);
// 			Element conf = DocumentHelper.createElement("config");
// 			conf.addAttribute(new QName("name"), name);
// 			conf.addAttribute(new QName("value"), value);
// 			root.add(conf);
// 		}
// 		doc.setRootElement(root);
// 
// 		OutputFormat format = OutputFormat.createPrettyPrint();
// 		format.setEncoding("UTF-8"); // 指定XML编码
// 		XMLWriter writer = new XMLWriter(new FileWriter(filePath), format);
// 		writer.write(doc);
// 		writer.close();
// 	}
// 
// 	public String get(String name) {
// 		return conf.get(name);
// 	}
// 
// 	public String set(String name, String value) {
// 		return conf.put(name, value);
// 	}
// 
// 	public static class ConfigName {
// 		public static final String dbPath = "dbPath";
// 		public static final String assetsPath = "assetsPath";
// 	}
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/config/SIFConfig.java
// public static class ConfigName {
// 	public static final String dbPath = "dbPath";
// 	public static final String assetsPath = "assetsPath";
// }
// 
// Path: src/main/java/me/xwang1024/sifResExplorer/data/ImagDao.java
// public interface ImagDao {
// 	public BufferedImage getImage(String imagPath) throws IOException;
// 	
// 	public BufferedImage getImageWithoutSplit(String texbPath) throws IOException;
// 	
// 	public String getRefTextureFilePath(String imagPath) throws IOException;
// 	
// 	public List<String> getImagList();
// 	
// 	public List<String> getTexbList();
// }


// Path: src/main/java/me/xwang1024/sifResExplorer/data/impl/ImagDaoImpl.java
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.Inflater;
import javax.imageio.ImageIO;
import me.xwang1024.sifResExplorer.config.SIFConfig;
import me.xwang1024.sifResExplorer.config.SIFConfig.ConfigName;
import me.xwang1024.sifResExplorer.data.ImagDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

		BufferedImage cache = null;
		for (Timg img : texture.image) {
			long x1 = img.vertices[0].u;
			long y1 = img.vertices[0].v;
			long x2 = img.vertices[img.vertexLen - 1].u;
			long y2 = img.vertices[img.vertexLen - 1].v;
			BufferedImage bimg = image.getSubimage((int) x1, (int) y1, (int) (x2 - x1),
					(int) (y2 - y1));
			String pngPath = img.path.replaceAll("\\.imag.*$", "");
			File pngFile = new File(tempDir, pngPath);
			System.out.println(pngFile.getAbsolutePath());
			pngFile.getParentFile().mkdirs();
			try {
				ImageIO.write(bimg, "png", pngFile);
			} catch (IOException e) {
				logger.error("{} temp file write error.", pngFile.getAbsolutePath());
				e.printStackTrace();
				continue;
			}
			if (img.path.contains(this.imagPath)) {
				cache = bimg;
			} else {
				logger.debug("{}:{}", img.path, this.imagPath);
			}
		}
		return cache;
	}

	private Texb extractTexb(String texbPath) throws IOException {
		// 构造texb文件的位置

		String assetsPath = SIFConfig.getInstance().get(ConfigName.assetsPath);
