public ImageType Classify(IntPtr pimg, int width, int height, int linesize) { if (width < Properties.Settings.Default.minWidth || height < Properties.Settings.Default.minHeight) { return(ImageType.Normal); } lock (syncRoot) { float[] ratio = new float[8]; log.Info("Classify Image: " + pimg + " w: " + width + " h: " + height + " linesize: " + linesize); int ret = ClassifyImage(classifier_handle_, pimg, width, height, linesize, 3, ratio.Length, ratio); log.Info("Classify Image Over!"); // Unlock the bits. float pornRatio = ratio[(int)InternalImageType.P**n]; float sexyRatio = ratio[(int)InternalImageType.Sexy]; int[] indices = new int[ratio.Length]; for (int i = 0; i < indices.Length; i++) { indices[i] = i; } Array.Sort(ratio, indices); InternalImageType imt = (InternalImageType)indices[indices.Length - 1]; float maxRatio = ratio[indices.Length - 1]; if (imt == InternalImageType.P**n && maxRatio > 0.5f) { return(ImageType.P**n); } else if ((imt == InternalImageType.PornGrayCartoon || imt == InternalImageType.PornColorCartoon) && maxRatio > 0.9f) { return(ImageType.P**n); } else if (imt == InternalImageType.Sexy && pornRatio + sexyRatio > 0.8) { return(ImageType.Disguise); } else { return(ImageType.Normal); } } }
private bool GetTextureImageFromMFString2(string mfstring) { Rectangle imgRect; int[] textureMaxSize; int glTexWidth; int glTexHeight; string[] urls; object resource; bool actually_loaded_something; if (X3DTypeConverters.IsMFString(mfstring)) { actually_loaded_something = false; urls = X3DTypeConverters.GetMFString(mfstring); foreach (string url in urls) { if (SceneManager.FetchSingle(url, out resource)) { Stream s; s = (Stream)resource; this.image = new Bitmap(s); s.Close(); actually_loaded_something = true; break; } } if (!actually_loaded_something) { this.image = Properties.Resources.ErrorTexture; } } else { this.image = new Bitmap(mfstring); } if (this.image == null) { return(false); } /* Get the maximum texture size supported by OpenGL: */ textureMaxSize = new int[] { 0 }; GL.GetInteger(GetPName.MaxTextureSize, textureMaxSize); //gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE,textureMaxSize); /* Find the target width and height sizes, which is just the highest * posible power of two that'll fit into the image. */ glTexWidth = textureMaxSize[0]; glTexHeight = textureMaxSize[0]; for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Width < size) { glTexWidth = size / 2; break; } if (image.Width == size) { glTexWidth = size; } } for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Height < size) { glTexHeight = size / 2; break; } if (image.Height == size) { glTexHeight = size; } } if (image.Width != glTexWidth || image.Height != glTexHeight) { /* Scale the image according to OpenGL requirements */ Image newImage = image.GetThumbnailImage(glTexWidth, glTexHeight, null, IntPtr.Zero); image.Dispose(); image = (Bitmap)newImage; } //if(file.ToLower().EndsWith(".bmp")) { image.RotateFlip(RotateFlipType.RotateNoneFlipY); //TODO: figure out more efficient code /* Another way to rotate texture on draw() * gl.MatrixMode(OpenGL.GL_TEXTURE); * gl.LoadIdentity(); * gl.Scale(1.0f,-1.0f,1.0f); * gl.MatrixMode(OpenGL.GL_MODELVIEW); */ //} imgRect = new Rectangle(0, 0, image.Width, image.Height); pixelData = image.LockBits(imgRect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); pTexImage = pixelData.Scan0; Width = image.Width; Height = image.Height; _type = InternalImageType.WindowsHandle; return(true); }
private bool GetTextureImageFromWindowsFileSystem(string file) { // Try and load the bitmap. Return false on failure. Bitmap image = new Bitmap(file); if (image == null) { return(false); } // Get the maximum texture size supported by OpenGL. int[] textureMaxSize = { 0 }; GL.GetInteger(GetPName.MaxTextureSize, textureMaxSize); //gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE,textureMaxSize); // Find the target width and height sizes, which is just the highest // posible power of two that'll fit into the image. int targetWidth = textureMaxSize[0]; int targetHeight = textureMaxSize[0]; for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Width < size) { targetWidth = size / 2; break; } if (image.Width == size) { targetWidth = size; } } for (int size = 1; size <= textureMaxSize[0]; size *= 2) { if (image.Height < size) { targetHeight = size / 2; break; } if (image.Height == size) { targetHeight = size; } } // If need to scale, do so now. if (image.Width != targetWidth || image.Height != targetHeight) { // Resize the image. Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero); // Destory the old image, and reset. image.Dispose(); image = (Bitmap)newImage; } // Lock the image bits (so that we can pass them to OGL). BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // Bind our texture object (make it the current texture). //this.Bind(); // Set the image data. //gl.TexImage2D(OpenGL.GL_TEXTURE_2D,0,(int)OpenGL.GL_RGBA, // width,height,0,OpenGL.GL_BGRA,OpenGL.GL_UNSIGNED_BYTE, // bitmapData.Scan0); this.Height = image.Height; this.Width = image.Width; this.pixelData = bitmapData; this.image = image; this.pTexImage = bitmapData.Scan0; // Unlock the image. //image.UnlockBits(bitmapData); // Dispose of the image file. //image.Dispose(); _type = InternalImageType.WindowsHandle; return(true); }
private bool GetTextureImageFromMFString(string mfstring) { Rectangle imgRect; int[] textureMaxSize; int glTexWidth; int glTexHeight; string[] urls; object resource; bool actually_loaded_something; actually_loaded_something = false; urls = X3DTypeConverters.GetMFString(mfstring); foreach (string url in urls) { if (SceneManager.FetchSingle(url, out resource)) { if (resource is Stream) { Stream s; s = (Stream)resource; this.image = new Bitmap(s); s.Close(); actually_loaded_something = true; } else { throw new Exception("Resource is of unknown type, consider returning file streams instead"); } break; } } if (!actually_loaded_something) { this.image = Properties.Resources.ErrorTexture; } if (this.image == null) { return(false); } var newSize = GetTextureGLMaxSize(image); Rescale(ref image, newSize); //if(file.ToLower().EndsWith(".bmp")) { image.RotateFlip(RotateFlipType.RotateNoneFlipY); //TODO: figure out more efficient code /* Another way to rotate texture on draw() * gl.MatrixMode(OpenGL.GL_TEXTURE); * gl.LoadIdentity(); * gl.Scale(1.0f,-1.0f,1.0f); * gl.MatrixMode(OpenGL.GL_MODELVIEW); */ //} imgRect = new Rectangle(0, 0, image.Width, image.Height); pixelData = image.LockBits(imgRect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); pTexImage = pixelData.Scan0; Width = image.Width; Height = image.Height; _type = InternalImageType.WindowsHandle; return(true); }