AmaroK86.ImageFormat.DDS.resize C# (CSharp) Метод

resize() публичный Метод

public resize ( ) : byte[]
Результат byte[]
        public override byte[] resize()
        {
            byte[] buff = new byte[ImageDataSize(this.imgSize, this.format, this.BPP)];
            Buffer.BlockCopy(base.resize(), 0, buff, 0, buff.Length);
            return buff;
            //return base.resize();
        }

Usage Example

Пример #1
0
        // New methods!
        public void OneSizeFitsAll(String inputFile, bool resFix = false)
        {
            // forced lowresfix
            // resFix = true;

            if (!File.Exists(inputFile))
                throw new FileNotFoundException("Input texture not found at: " + inputFile);

            bool containsmips = true;
            ImageMipMapHandler mipmaps = null;

            if (imgList.Count > 1)
            {
                try{ mipmaps = new ImageMipMapHandler(inputFile, null); }
                catch (FormatException) { containsmips = false; }
            }
            else
                containsmips = false;

            ImageInfo existingImg = imgList.First(img => img.storageType != storage.empty);
            if (containsmips)
            {
                if ((float)mipmaps.imageList[0].imgSize.width / (float)mipmaps.imageList[0].imgSize.height != (float)existingImg.imgSize.width / (float)existingImg.imgSize.height)
                    throw new FormatException("Input texture not correct aspect ratio");

                if (mipmaps.imageList[0].format == "PF_R8G8B8") // Convert to 32-bit if necessary
                {
                    for (int i = 0; i < mipmaps.imageList.Count; i++)
                        mipmaps.imageList[i] = new DDS(null, mipmaps.imageList[i].imgSize, "A8R8G8B8", ImageMipMapHandler.ConvertTo32bit(mipmaps.imageList[i].resize(), (int)mipmaps.imageList[i].imgSize.width, (int)mipmaps.imageList[i].imgSize.height));
                }

                if (Class == class2 || Class == class3) // Allow format modification if one of the derived classes. Don't need the single level check since we're replacing all levels
                    ChangeFormat(mipmaps.imageList[0].format);

                if (texFormat == "PF_NormalMap_HQ") // Check formats
                {
                    if (mipmaps.imageList[0].format != "ATI2")
                        throw new FormatException("Texture not in correct format - Expected ATI2");
                }
                else if (String.Compare(texFormat, "PF_" + mipmaps.imageList[0].format, true) != 0)
                    throw new FormatException("Texture not in correct format - Expected " + texFormat);

                for (int i = mipmaps.imageList.Count - 1; i >= 0; i--)
                {
                    if (imgList.Exists(img => img.imgSize == mipmaps.imageList[i].imgSize))
                        ReplaceImage(mipmaps.imageList[i]);
                    else if (mipmaps.imageList[i].imgSize.width > imgList.First().imgSize.width && mipmaps.imageList[i].imgSize.height > imgList.First().imgSize.height)
                        UpscaleImage(mipmaps.imageList[i]);
                    //else
                    //    AddMissingImage(mipmaps.imageList[i]);
                    // Else ignore missing values
                }

                while (imgList[0].imgSize.width > mipmaps.imageList[0].imgSize.width) // Remove any existing higher levels
                    imgList.RemoveAt(0);
            }
            else
            {
                ImageFile ddsfile = new DDS(inputFile, null);
                
                if ((float)ddsfile.imgSize.width / (float)ddsfile.imgSize.height != (float)existingImg.imgSize.width / (float)existingImg.imgSize.height) // Check dimensions
                    throw new FormatException("Input texture not correct aspect ratio");

                if (ddsfile.format == "R8G8B8")
                    ddsfile = new DDS(null, ddsfile.imgSize, "A8R8G8B8", ImageMipMapHandler.ConvertTo32bit(ddsfile.resize(), (int)ddsfile.imgSize.width, (int)ddsfile.imgSize.height));

                if (imgList.Count == 1 && (Class == class2 || Class == class3)) // Since this is single level replacement, only allow format change if a single level texture with required class
                    ChangeFormat(ddsfile.format);

                if (texFormat == "PF_NormalMap_HQ") // Check format
                {
                    if (ddsfile.format != "ATI2")
                        throw new FormatException("Texture not in correct format - Expected ATI2");
                }
                else if (String.Compare(texFormat, "PF_" + ddsfile.format, true) != 0)
                    throw new FormatException("Texture not in correct format - Expected " + texFormat);

                if (imgList.Count == 1 && imgList[0].imgSize != ddsfile.imgSize) // If img doesn't exist and it's a single level texture, use hard replace
                    HardReplaceImage(ddsfile);
                else if (imgList.Exists(img => img.imgSize == ddsfile.imgSize)) // Catches the rest of the single levels and every one which has an existing reference for that level
                    ReplaceImage(ddsfile);
                else if (ddsfile.imgSize.width > imgList[0].imgSize.width) // Add a greater image
                    UpscaleImage(ddsfile);
                //else if (ddsfile.imgSize.width < imgList.Last().imgSize.width) // Add a smaller image
                //    AddMissingImage(ddsfile);
            }

            if (imgList.Count > 1 && resFix)
                LowResFix();

            // Fix up properties
            if (properties.ContainsKey("SizeX"))
                properties["SizeX"].Value.IntValue = (int)imgList.First(img => img.storageType != storage.empty).imgSize.width;
            if (properties.ContainsKey("SizeY"))
                properties["SizeY"].Value.IntValue = (int)imgList.First(img => img.storageType != storage.empty).imgSize.height;
            if (properties.ContainsKey("MipTailBaseIdx"))
                properties["MipTailBaseIdx"].Value.IntValue = imgList.Count - 1;
            numMipMaps = (uint)imgList.Count;
        }
All Usage Examples Of AmaroK86.ImageFormat.DDS::resize