public byte[] extractImage(ImageInfo imgInfo, bool NoOutput, string archiveDir = null, string fileName = null)
{
ImageFile imgFile;
if (fileName == null)
{
fileName = texName + "_" + imgInfo.imgSize + getFileFormat();
}
byte[] imgBuffer = null;
switch (imgInfo.storageType)
{
case storage.pccSto:
imgBuffer = new byte[imgInfo.uncSize];
Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize);
break;
case storage.arcCpr:
case storage.arcUnc:
string archivePath = FullArcPath;
if (String.IsNullOrEmpty(archivePath))
archivePath = GetTexArchive(archiveDir);
if (!File.Exists(archivePath))
{
throw new FileNotFoundException("Texture archive not found in " + archivePath);
}
using (FileStream archiveStream = File.OpenRead(archivePath))
{
if (imgInfo.storageType == storage.arcCpr)
{
SaltLZOHelper lzohelp = new SaltLZOHelper();
imgBuffer = lzohelp.DecompressTex(archiveStream, imgInfo.offset, imgInfo.uncSize, imgInfo.cprSize);
}
else
{
archiveStream.Seek(imgInfo.offset, SeekOrigin.Begin);
imgBuffer = new byte[imgInfo.uncSize];
archiveStream.Read(imgBuffer, 0, imgBuffer.Length);
}
}
break;
default:
throw new FormatException("Unsupported texture storage type");
}
imgFile = new DDS(fileName, imgInfo.imgSize, Textures.Methods.StringifyFormat(texFormat), imgBuffer);
byte[] saveImg = imgFile.ToArray();
if (!NoOutput)
using (FileStream outputImg = new FileStream(imgFile.fileName, FileMode.Create, FileAccess.Write))
outputImg.Write(saveImg, 0, saveImg.Length);
return saveImg;
}