Exemplo n.º 1
0
        public BaseBitmap GetUpdateRegionBitmap()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_GetUpdateRegionBitmap__SWIG_0(swigCPtr);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 2
0
        public BaseBitmap Read()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.MovieLoader_Read__SWIG_2(swigCPtr);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 3
0
        public BaseBitmap Read(int new_frame_idx, SWIGTYPE_p_Int32 _result)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.MovieLoader_Read__SWIG_0(swigCPtr, new_frame_idx, SWIGTYPE_p_Int32.getCPtr(_result));
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 4
0
        public BaseBitmap AddChannel(bool arg0, bool straight)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_AddChannel(swigCPtr, arg0, straight);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 5
0
        } /* <Vector_csout> */

        public BaseBitmap GetBitmap()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseShader_GetBitmap(swigCPtr);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 6
0
        public BaseBitmap GetDefaultOperatorIcon(GvOperatorType type)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.GvWorld_GetDefaultOperatorIcon(swigCPtr, (int)type);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 7
0
        public BaseBitmap GetClonePart(int x, int y, int w, int h)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_GetClonePart(swigCPtr, x, y, w, h);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 8
0
        private static void GenerateUncompressedMipMaps(BaseBitmap bitmap)
        {
            int channelCount;

            switch (bitmap.Format)
            {
            case BitmapFormat.A8Y8:
            case BitmapFormat.V8U8:
                channelCount = 2;
                break;

            case BitmapFormat.Y8:
            case BitmapFormat.A8:
                channelCount = 1;
                break;

            case BitmapFormat.A8R8G8B8:
            case BitmapFormat.X8R8G8B8:
                channelCount = 4;
                break;

            default:
                bitmap.MipMapCount = 0;
                return;
            }
            MipMapGenerator generator = new MipMapGenerator();

            generator.GenerateMipMap(bitmap.Height, bitmap.Width, bitmap.Data, channelCount);
            bitmap.MipMapCount = generator.MipMaps.Count;
            bitmap.Data        = generator.CombineImage(bitmap.Data);
            return;
        }
Exemplo n.º 9
0
        public static BaseBitmap Alloc()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_Alloc();
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 10
0
        public static BaseBitmap AutoBitmap(int id)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_AutoBitmap__SWIG_1(id);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 11
0
        public BaseBitmap GetInternalChannel()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_GetInternalChannel__SWIG_0(swigCPtr);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 12
0
        public BaseBitmap GetChannelNum(int num)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_GetChannelNum__SWIG_0(swigCPtr, num);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 13
0
        public BaseBitmap GetPreview(int flags)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseMaterial_GetPreview(swigCPtr, flags);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 14
0
        private static void GenerateMipMaps(BaseBitmap bitmap)
        {
            switch (bitmap.Format)
            {
            case BitmapFormat.Dxt1:
            case BitmapFormat.Dxt3:
            case BitmapFormat.Dxt5:
            case BitmapFormat.Dxn:
                GenerateCompressedMipMaps(bitmap);
                break;

            case BitmapFormat.A8Y8:
            case BitmapFormat.Y8:
            case BitmapFormat.A8:
            case BitmapFormat.A8R8G8B8:
            case BitmapFormat.V8U8:
            case BitmapFormat.X8R8G8B8:
                GenerateUncompressedMipMaps(bitmap);
                break;

            case BitmapFormat.A4R4G4B4:
            case BitmapFormat.R5G6B5:
            case BitmapFormat.A16B16G16R16F:
            case BitmapFormat.A32B32G32R32F:
                bitmap.MipMapCount = 0;
                break;

            default:
                throw new Exception($"Unsupported format for mipmap generation {bitmap.Format}");
            }
        }
Exemplo n.º 15
0
        public Texture(Stream file_t, string filename)
        {
            if (file_t == null)
            {
                throw new ArgumentNullException(nameof(file_t));
            }
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }
            this.Path = filename;
            this.Data = IResourceExtentions.GetStreamData(file_t);
            using (file_t)
            {
                this.Acquire();
                if (TextureObject < 1)
                {
                    throw new GLInstanceNotCreated();
                }
                GL.BindTexture(TextureTarget.Texture2D, TextureObject);

                BaseBitmap bmp = new BaseBitmap(file_t);
                bmp.RotateY();
                Widith = bmp.Width;
                Height = bmp.Height;
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp.Width, bmp.Height, 0, OpenTK.Graphics.OpenGL4.PixelFormat.Rgba, PixelType.UnsignedByte, bmp.ColorMap);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.BindTexture(TextureTarget.Texture2D, 0);
            }
        }
Exemplo n.º 16
0
        public static MultipassBitmap AllocWrapper(BaseBitmap bmp)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.MultipassBitmap_AllocWrapper(BaseBitmap.getCPtr(bmp));
            MultipassBitmap       ret  = (cPtr == global::System.IntPtr.Zero) ? null : new MultipassBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 17
0
        } /* </String_csout> */

        public virtual BaseBitmap GetPortIcon(GvNode bn, int id, GvLayoutType layout_type)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.GvOperatorData_GetPortIcon(swigCPtr, GvNode.getCPtr(bn), id, (int)layout_type);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            return(ret);
        }
Exemplo n.º 18
0
        public IMAGERESULT Open(Filename name, BaseBitmap bm, int fps, int format, BaseContainer data, SAVEBIT savebits)
        {
            IMAGERESULT ret = (IMAGERESULT)C4dApiPINVOKE.MovieSaver_Open__SWIG_1(swigCPtr, Filename.getCPtr(name), BaseBitmap.getCPtr(bm), fps, format, BaseContainer.getCPtr(data), (int)savebits);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 19
0
 public BaseBitmap(BaseBitmap bitmap)
 {
     Height      = bitmap.Height;
     Width       = bitmap.Width;
     Depth       = bitmap.Depth;
     MipMapCount = bitmap.MipMapCount;
     Type        = bitmap.Type;
     Flags       = bitmap.Flags;
     UpdateFormat(bitmap.Format);
 }
Exemplo n.º 20
0
        public virtual IMAGERESULT Load(Filename name, BaseBitmap bm, int frame)
        {
            IMAGERESULT ret = (IMAGERESULT)C4dApiPINVOKE.BitmapLoaderData_Load(swigCPtr, Filename.getCPtr(name), BaseBitmap.getCPtr(bm), frame);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 21
0
        public virtual IMAGERESULT Save(Filename name, BaseBitmap bm, BaseContainer data, SAVEBIT savebits)
        {
            IMAGERESULT ret = (IMAGERESULT)(SwigDerivedClassHasMethod("Save", swigMethodTypes0) ? C4dApiPINVOKE.BitmapSaverData_SaveSwigExplicitBitmapSaverData(swigCPtr, Filename.getCPtr(name), BaseBitmap.getCPtr(bm), BaseContainer.getCPtr(data), (int)savebits) : C4dApiPINVOKE.BitmapSaverData_Save(swigCPtr, Filename.getCPtr(name), BaseBitmap.getCPtr(bm), BaseContainer.getCPtr(data), (int)savebits));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 22
0
        public static BaseBitmap AutoBitmap(string /* constString&_cstype */ str)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BaseBitmap_AutoBitmap__SWIG_0(str);
            BaseBitmap            ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BaseBitmap(cPtr, false);

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Exemplo n.º 23
0
        private static void FlipImage(BaseBitmap bitmap, Bitmap.Image image)
        {
            switch (image.Format)
            {
            case BitmapFormat.Dxt1:
            case BitmapFormat.Dxt3:
            case BitmapFormat.Dxt5:
            case BitmapFormat.Dxn:
                for (int j = 0; j < bitmap.Data.Length; j += 2)
                {
                    Array.Reverse(bitmap.Data, j, 2);
                }
                break;

            case BitmapFormat.AY8:
            case BitmapFormat.Y8:
            case BitmapFormat.A8:
            case BitmapFormat.Dxt5aMono:
            case BitmapFormat.Dxt3aMono:
            case BitmapFormat.Dxt3aAlpha:
            case BitmapFormat.Dxt5aAlpha:
            case BitmapFormat.Ctx1:
            case BitmapFormat.DxnMonoAlpha:
            case BitmapFormat.Dxt5a:
            case BitmapFormat.R5G6B5:
            case BitmapFormat.A4R4G4B4:
                break;

            case BitmapFormat.A8R8G8B8:
            case BitmapFormat.X8R8G8B8:
                for (int j = 0; j < bitmap.Data.Length; j += 4)
                {
                    Array.Reverse(bitmap.Data, j, 4);
                }
                break;

            case BitmapFormat.A16B16G16R16F:
            case BitmapFormat.A8Y8:
            case BitmapFormat.V8U8:
                for (int j = 0; j < bitmap.Data.Length; j += 2)
                {
                    Array.Reverse(bitmap.Data, j, 2);
                }
                break;

            default:
                throw new Exception($"Unsupported format {image.Format} flipping");
            }

            if (bitmap.Format == BitmapFormat.Dxn)
            {
                bitmap.Data = BitmapDecoder.SwapXYDxn(bitmap.Data, bitmap.Width, bitmap.Height);
            }
        }
Exemplo n.º 24
0
 private void SetResourceDefinitionData(BaseBitmap bitmap, Bitmap.Image image, BitmapTextureInteropResource.BitmapDefinition definition)
 {
     definition.Data        = new TagData(bitmap.Data.Length, new CacheAddress(CacheAddressType.Resource, 0));
     definition.Width       = (short)bitmap.Width;
     definition.Height      = (short)bitmap.Height;
     definition.Depth       = (sbyte)bitmap.Depth;
     definition.MipmapCount = (sbyte)(bitmap.MipMapCount + 1);
     definition.Type        = bitmap.Type;
     definition.D3DFormat   = GetUnusedFormat(bitmap.Format);
     definition.Format      = bitmap.Format;
     definition.Curve       = image.Curve;
     definition.Flags       = bitmap.Flags;
 }
Exemplo n.º 25
0
        private TagResourceReference ConvertBitmap(Bitmap bitmap, Dictionary <ResourceLocation, Stream> resourceStreams, int imageIndex, string tagName)
        {
            BaseBitmap baseBitmap = BitmapConverter.ConvertGen3Bitmap(BlamCache, bitmap, imageIndex);

            if (baseBitmap == null)
            {
                return(null);
            }

            BitmapUtils.SetBitmapImageData(baseBitmap, bitmap.Images[imageIndex]);
            var bitmapResourceDefinition = BitmapUtils.CreateBitmapTextureInteropResource(baseBitmap);
            var resourceReference        = CacheContext.ResourceCache.CreateBitmapResource(bitmapResourceDefinition);

            return(resourceReference);
        }
Exemplo n.º 26
0
        private void ExtractBitmap(CacheFile.IndexItem blamTag, string directory)
        {
            Console.WriteLine($"{blamTag.Name}");
            //
            // Load the Blam tag definition
            //

            var blamContext = new CacheSerializationContext(ref BlamCache, blamTag);

            var bitmap = BlamCache.Deserializer.Deserialize <Bitmap>(blamContext);


            var    ddsOutDir   = directory;
            string bitmap_name = blamTag.Name.Replace('\\', '_');

            if (bitmap.Images.Count > 1)
            {
                ddsOutDir = Path.Combine(directory, bitmap_name);
                Directory.CreateDirectory(ddsOutDir);
            }

            for (var i = 0; i < bitmap.Images.Count; i++)
            {
                var outPath = Path.Combine(ddsOutDir, ((bitmap.Images.Count > 1) ? i.ToString() : bitmap_name) + ".dds");
                var image   = bitmap.Images[i];
                //
                // Get bitmap data and write file
                //

                BaseBitmap baseBitmap = ExtractBitmapData(bitmap, i);

                // Bitmap is not valid (not a failure to convert, tag data is not valid / no data to convert
                if (baseBitmap == null)
                {
                    return;
                }

                var header = new DDSHeader(baseBitmap);


                using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
                {
                    header.Write(new EndianWriter(outStream));
                    var dataStream = new MemoryStream(baseBitmap.Data);
                    StreamUtil.Copy(dataStream, outStream, baseBitmap.Data.Length);
                }
            }
        }
Exemplo n.º 27
0
        private void SetTagData(BaseBitmap bitmap, Bitmap.Image image)
        {
            image.Width       = (short)bitmap.Width;
            image.Height      = (short)bitmap.Height;
            image.Depth       = (sbyte)bitmap.Depth;
            image.Format      = bitmap.Format;
            image.Type        = bitmap.Type;
            image.MipmapCount = (sbyte)bitmap.MipMapCount;
            image.DataSize    = bitmap.Data.Length;
            image.XboxFlags   = BitmapFlagsXbox.None;
            image.Flags       = bitmap.Flags;

            if (image.Format == BitmapFormat.Dxn)
            {
                image.Flags |= BitmapFlags.Unknown3;
            }
        }
Exemplo n.º 28
0
        private string GetTexture(BaseContainer data, BaseChannel matChannel)
        {
            string resultName = null;
            string texture    = data.GetString(C4dApi.BASECHANNEL_TEXTURE);

            if (!string.IsNullOrEmpty(texture))
            {
                texture    = Path.GetFileNameWithoutExtension(texture);
                texture   += ".jpg";
                resultName = texture;

                if (!_textureFiles.Contains(texture))
                {
                    matChannel.InitTexture(new InitRenderStruct(_doc));
                    using (BaseBitmap bitmap = matChannel.GetBitmap())
                    {
                        if (bitmap != null)
                        {
                            using (BaseContainer compressionContainer = new BaseContainer(C4dApi.JPGSAVER_QUALITY))
                            {
                                bool bRet = bitmap.SetColorProfile(ColorProfile.GetDefaultSRGB());
                                compressionContainer.SetFloat(C4dApi.JPGSAVER_QUALITY, 70.0);
                                string textureFileAbs = Path.Combine(_sceneRootDir, texture);
                                bitmap.Save(new Filename(textureFileAbs), C4dApi.FILTER_JPG, compressionContainer,
                                            SAVEBIT.SAVEBIT_0);
                                _textureFiles.Add(texture);
                            }
                        }
                        else
                        {
                            resultName = null;
                        }
                    }
                    matChannel.FreeTexture();
                }
            }
            return(resultName);
        }
Exemplo n.º 29
0
        public static int GetMipMapSize(BaseBitmap blamBitmap)
        {
            int pixelCount  = 0;
            var mipMapCount = blamBitmap.MipMapCount;

            if (blamBitmap.MipMapCount > 0)
            {
                int previousHeight = blamBitmap.Height;
                int previousWidth  = blamBitmap.Width;

                for (int i = 0; i < mipMapCount; i++)
                {
                    var mipMapHeight = previousHeight / 2;
                    var mipMapWidth  = previousWidth / 2;

                    previousHeight /= 2;
                    previousWidth  /= 2;

                    pixelCount += mipMapHeight * mipMapWidth;
                }
            }
            return((int)(pixelCount / blamBitmap.CompressionFactor));
        }
Exemplo n.º 30
0
        private static BaseBitmap ConvertGen3Bitmap(byte[] primaryData, byte[] secondaryData, BitmapTextureInteropDefinition definition, Bitmap bitmap, int imageIndex, bool isPaired, int pairIndex, BitmapTextureInteropDefinition otherDefinition, bool forDDS)
        {
            if (primaryData == null && secondaryData == null)
            {
                return(null);
            }

            using (var result = new MemoryStream())
            {
                int mipLevelCount = definition.MipmapCount;
                int layerCount    = definition.BitmapType == BitmapType.CubeMap ? 6 : definition.Depth;

                if (definition.BitmapType == BitmapType.Array && mipLevelCount > 1)
                {
                    mipLevelCount          = 1;
                    definition.MipmapCount = 1;
                }

                if (!forDDS)
                {
                    // order for d3d9, all faces first, then mipmaps
                    for (int mipLevel = 0; mipLevel < mipLevelCount; mipLevel++)
                    {
                        for (int layerIndex = 0; layerIndex < layerCount; layerIndex++)
                        {
                            if (definition.BitmapType == BitmapType.CubeMap) // swap cubemap faces
                            {
                                if (layerIndex == 2)
                                {
                                    layerIndex = 3;
                                }
                                else if (layerIndex == 3)
                                {
                                    layerIndex = 2;
                                }
                            }

                            ConvertGen3BitmapData(result, primaryData, secondaryData, definition, bitmap, imageIndex, mipLevel, layerIndex, isPaired, pairIndex, otherDefinition);

                            if (definition.BitmapType == BitmapType.CubeMap)
                            {
                                if (layerIndex == 3)
                                {
                                    layerIndex = 2;
                                }
                                else if (layerIndex == 2)
                                {
                                    layerIndex = 3;
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int layerIndex = 0; layerIndex < layerCount; layerIndex++)
                    {
                        if (definition.BitmapType == BitmapType.CubeMap) // swap cubemap faces
                        {
                            if (layerIndex == 2)
                            {
                                layerIndex = 3;
                            }
                            else if (layerIndex == 3)
                            {
                                layerIndex = 2;
                            }
                        }

                        for (int mipLevel = 0; mipLevel < mipLevelCount; mipLevel++)
                        {
                            ConvertGen3BitmapData(result, primaryData, secondaryData, definition, bitmap, imageIndex, mipLevel, layerIndex, isPaired, pairIndex, otherDefinition);
                        }

                        if (definition.BitmapType == BitmapType.CubeMap)
                        {
                            if (layerIndex == 3)
                            {
                                layerIndex = 2;
                            }
                            else if (layerIndex == 2)
                            {
                                layerIndex = 3;
                            }
                        }
                    }
                }

                var resultData = result.ToArray();

                BaseBitmap resultBitmap = new BaseBitmap(bitmap.Images[imageIndex]);


                var newFormat = BitmapUtils.GetEquivalentBitmapFormat(bitmap.Images[imageIndex].Format);
                resultBitmap.UpdateFormat(newFormat);

                if (BitmapUtils.RequiresDecompression(resultBitmap.Format, (uint)resultBitmap.Width, (uint)resultBitmap.Height))
                {
                    resultBitmap.Format = BitmapFormat.A8R8G8B8;
                }

                if (!BitmapUtils.IsCompressedFormat(resultBitmap.Format))
                {
                    resultBitmap.Flags &= ~BitmapFlags.Compressed;
                }
                else
                {
                    resultBitmap.Flags |= BitmapFlags.Compressed;
                }

                //
                // Update resource definition/image, truncate DXN to level 4x4
                //

                resultBitmap.Data = resultData;

                if (resultBitmap.Format == BitmapFormat.Dxn) // wouldn't be required if d3d9 supported non power of two DXN and with mips less than 8x8
                {
                    GenerateCompressedMipMaps(resultBitmap);
                }


                if (resultBitmap.Type == BitmapType.Array) // for HO, arrays use the index of Texture3D
                {
                    resultBitmap.Type = BitmapType.Texture3D;
                }

                return(resultBitmap);
            }
        }