예제 #1
0
        /// <summary>
        /// Rescales the specified image.
        /// </summary>
        /// <remarks>
        /// The MipmapCount will be reset to 1 after this operation
        /// </remarks>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="rescale">The rescale.</param>
        private void Rescale(TexImage image, FreeImageTextureLibraryData libraryData, RescalingRequest rescale)
        {
            int width = rescale.ComputeWidth(image);
            int height = rescale.ComputeHeight(image);

            Log.Info("Rescaling image to " + width + "x" + height + " with " + rescale.Filter + " ...");

            FIBITMAP[] newTab;

            if (image.Dimension == TexImage.TextureDimension.Texture3D) // in case of 3D Texture, we must rescale each slice of the top mipmap level
            {
                newTab = new FIBITMAP[image.ArraySize * image.FaceCount * image.Depth];
                int curDepth;

                int nbSubImageWithMipMapPerArrayMemeber = 0; // calculating the number of sub images we have to jump to reach the next top level mipmap of the next array member
                curDepth = image.Depth;
                for (int i = 0; i < image.MipmapCount; ++i)
                {
                    nbSubImageWithMipMapPerArrayMemeber += curDepth;
                    curDepth = curDepth > 1 ? curDepth >>= 1 : curDepth;
                }

                int ct = 0;
                for (int j = 0; j < image.ArraySize; ++j)
                {
                    for (int i = 0; i < image.Depth; ++i)
                    {
                        newTab[ct] = FreeImage.Rescale(libraryData.Bitmaps[i + j * nbSubImageWithMipMapPerArrayMemeber], width, height, (FREE_IMAGE_FILTER)rescale.Filter);
                        ++ct;
                    }
                }
            }
            else
            {
                newTab = new FIBITMAP[image.ArraySize];
                int ct = 0;
                for (int i = 0; i < libraryData.Bitmaps.Length; i += image.MipmapCount)
                {
                    newTab[ct] = FreeImage.Rescale(libraryData.Bitmaps[i], width, height, (FREE_IMAGE_FILTER)rescale.Filter);
                    ++ct;
                }
            }

            for (int i = 0; i < libraryData.Bitmaps.Length; ++i)
            {
                FreeImage.Unload(libraryData.Bitmaps[i]);
            }

            libraryData.Bitmaps = newTab;
            image.Data = FreeImage.GetBits(newTab[0]);

            // Updating image data
            image.Rescale(width, height);

            int rowPitch, slicePitch;
            Tools.ComputePitch(image.Format, width, height, out rowPitch, out slicePitch);
            
            image.RowPitch = rowPitch;
            image.SlicePitch = slicePitch;
            image.MipmapCount = 1;
            image.DataSize = image.SlicePitch * image.ArraySize * image.FaceCount * image.Depth;
        }
예제 #2
0
파일: DxtTexLib.cs 프로젝트: releed/paradox
        /// <summary>
        /// Rescales the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="request">The request.</param>
        /// <exception cref="TexLibraryException">Rescaling failed</exception>
        private void Rescale(TexImage image, DxtTextureLibraryData libraryData, RescalingRequest request)
        {
            int width = request.ComputeWidth(image);
            int height = request.ComputeHeight(image);

            Log.Info("Rescaling to " + width + "x" + height + " ...");

            TEX_FILTER_FLAGS filter;
            switch(request.Filter)
            {
                case Filter.Rescaling.Bilinear:
                    filter = TEX_FILTER_FLAGS.TEX_FILTER_LINEAR;
                    break;
                case Filter.Rescaling.Bicubic:
                    filter = TEX_FILTER_FLAGS.TEX_FILTER_CUBIC;
                    break;
                case Filter.Rescaling.Box:
                    filter = TEX_FILTER_FLAGS.TEX_FILTER_FANT;
                    break;
                case Filter.Rescaling.Nearest:
                    filter = TEX_FILTER_FLAGS.TEX_FILTER_POINT;
                    break;
                default:
                    filter = TEX_FILTER_FLAGS.TEX_FILTER_FANT;
                    break;
            }

            ScratchImage scratchImage = new ScratchImage();
            HRESULT hr = Utilities.Resize(libraryData.DxtImages, libraryData.DxtImages.Length, ref libraryData.Metadata, width, height, filter, scratchImage);

            if (hr != HRESULT.S_OK)
            {
                Log.Error("Rescaling failed: " + hr);
                throw new TextureToolsException("Rescaling failed: " + hr);
            }

            // Freeing Memory
            if (image.DisposingLibrary != null) image.DisposingLibrary.Dispose(image);

            // Updating image data
            image.Rescale(width, height);

            libraryData.Image = scratchImage;
            libraryData.DxtImages = libraryData.Image.GetImages();
            libraryData.Metadata = libraryData.Image.metadata;
            image.DisposingLibrary = this;

            UpdateImage(image, libraryData);
        }
예제 #3
0
        /// <summary>
        /// Rescales the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="request">The request.</param>
        private void Rescale(TexImage image, PvrTextureLibraryData libraryData, RescalingRequest request)
        {
            int width = request.ComputeWidth(image);
            int height = request.ComputeHeight(image);

            Log.Info("Rescaling to " + width + "x" + height + " ...");

            EResizeMode filter;
            switch(request.Filter)
            {
                case Filter.Rescaling.Bilinear:
                    filter = EResizeMode.eResizeLinear;
                    break;
                case Filter.Rescaling.Bicubic:
                    filter = EResizeMode.eResizeCubic;
                    break;
                case Filter.Rescaling.Nearest:
                    filter = EResizeMode.eResizeNearest;
                    break;
                default:
                    filter = EResizeMode.eResizeCubic;
                    break;
            }

            Utilities.Resize(libraryData.Texture, (uint)width, (uint)height, (uint)image.Depth, filter);
            UpdateImage(image, libraryData);

            // Updating image data
            image.Rescale(width, height);
        }