public unsafe void SetPixel(int x, int y, ColorEx color) { fixed(byte *bytebuf = pixelData) { PixelUtil.PackColor(color.r, color.g, color.b, color.a, format, bytebuf + ComputeOffset(x, y)); } }
public override Media.PixelFormat GetNativeFormat(Graphics.TextureType ttype, Media.PixelFormat format, Graphics.TextureUsage usage) { var caps = Root.Instance.RenderSystem.Capabilities; //Check compressed texture support //if a compressed formt not supported, rever to PixelFormat.A8R8G8B8 if (PixelUtil.IsCompressed(format) && !caps.HasCapability(Graphics.Capabilities.TextureCompressionDXT) && !caps.HasCapability(Graphics.Capabilities.TextureCompressionPVRTC)) { return(PixelFormat.A8R8G8B8); } //if floating point texture not supported, rever to PixelFormat.A8R8G8B8 if (PixelUtil.IsFloatingPoint(format) && !caps.HasCapability(Graphics.Capabilities.TextureFloat)) { return(PixelFormat.A8R8G8B8); } //Check if this is a valid rendertarget format if ((usage & Graphics.TextureUsage.RenderTarget) == Graphics.TextureUsage.RenderTarget) { //Get closest supported alternative //if format is supported it's returned return(GLES2RTTManager.Instance.GetSupportedAlternative(format)); } //Supported return(format); }
private void EyeDropperButton_PreviewMouseMove(object sender, MouseEventArgs e) { var str = new Native.PointW(); Native.GetCursorPos(ref str); var image = Native.CaptureBitmapSource((int)_captureSize.Width, (int)_captureSize.Height, str.X - (int)(_captureSize.Width / 2d), str.Y - (int)(_captureSize.Height / 2d)); if (image.Format != PixelFormats.Bgra32) { image = new FormatConvertedBitmap(image, PixelFormats.Bgra32, null, 0); } EyeDropperImage.Source = image; var pix = new PixelUtil(image); pix.LockBits(); UpdateMarkerPosition(pix.GetPixel((int)(_captureSize.Width / 2d), (int)(_captureSize.Height / 2d))); #region Update the values _isUpdating = true; AlphaIntegerUpDown.Value = SelectedColor.A; RedIntegerUpDown.Value = SelectedColor.R; GreenIntegerUpDown.Value = SelectedColor.G; BlueIntegerUpDown.Value = SelectedColor.B; _isUpdating = false; #endregion pix.UnlockBits(); }
///<summary> /// Internal implementation of <see cref="HardwareBuffer.Lock"/>. ///</summary> protected override PixelBox LockImpl(BasicBox lockBox, BufferLocking options) { _lockedBox = lockBox; // Set extents and format var rval = new PixelBox(lockBox, Format); var sizeInBytes = PixelUtil.GetMemorySize(lockBox.Width, lockBox.Height, lockBox.Depth, XnaHelper.Convert(surface.Format)); if (_bufferBytes == null || _bufferBytes.Length != sizeInBytes) { _bufferBytes = new byte[sizeInBytes]; #if !SILVERLIGHT if (surface != null) { surface.GetData(mipLevel, XnaHelper.ToRectangle(lockBox), _bufferBytes, 0, _bufferBytes.Length); } else if (cube != null) { cube.GetData(face, mipLevel, XnaHelper.ToRectangle(lockBox), _bufferBytes, 0, _bufferBytes.Length); } else { volume.GetData(mipLevel, lockBox.Left, lockBox.Top, lockBox.Right, lockBox.Bottom, lockBox.Front, lockBox.Back, _bufferBytes, 0, _bufferBytes.Length); } #endif } rval.Data = BufferBase.Wrap(_bufferBytes); return(rval); }
public static Pixel getSaplingFromLeaves(Pixel leavesPixel) { if (leavesPixel == Pixels.LEAVES) { return(Pixels.SAPLING); } else if (leavesPixel == PixelUtil.getStateLeaf(1)) { return(PixelUtil.getStateSapling(1)); } else if (leavesPixel == PixelUtil.getStateLeaf(2)) { return(PixelUtil.getStateSapling(2)); } else if (leavesPixel == PixelUtil.getStateLeaf(3)) { return(PixelUtil.getStateSapling(3)); } else if (leavesPixel == Pixels.LEAVES2) { return(PixelUtil.getStateSapling(4)); } else if (leavesPixel == PixelUtil.getStateLeaf2(1)) { return(PixelUtil.getStateSapling(5)); } else { return(Pixels.SAPLING); } }
public virtual void ConvertToImage(out Image destImage, bool includeMipMaps) #endif { var numMips = includeMipMaps ? MipmapCount + 1 : 1; var dataSize = Image.CalculateSize(numMips, FaceCount, Width, Height, Depth, Format); var pixData = new byte[dataSize]; // if there are multiple faces and mipmaps we must pack them into the data // faces, then mips var currentPixData = BufferBase.Wrap(pixData); for (var face = 0; face < FaceCount; ++face) { for (var mip = 0; mip < numMips; ++mip) { var mipDataSize = PixelUtil.GetMemorySize(Width, Height, Depth, Format); var pixBox = new PixelBox(Width, Height, Depth, Format, currentPixData); GetBuffer(face, mip).BlitToMemory(pixBox); currentPixData += mipDataSize; } } currentPixData.Dispose(); // load, and tell Image to delete the memory when it's done. destImage = (new Image()).FromDynamicImage(pixData, Width, Height, Depth, Format, true, FaceCount, numMips - 1); }
public override PixelFormat GetNativeFormat(TextureType ttype, PixelFormat format, TextureUsage usage) { // Adjust requested parameters to capabilities RenderSystemCapabilities caps = Root.Instance.RenderSystem.Capabilities; // Check compressed texture support // if a compressed format not supported, revert to PF_A8R8G8B8 if (PixelUtil.IsCompressed(format) && !caps.HasCapability(Capabilities.TextureCompressionDXT)) { return(PixelFormat.A8R8G8B8); } // if floating point textures not supported, revert to PF_A8R8G8B8 if (PixelUtil.IsFloatingPoint(format) && !caps.HasCapability(Capabilities.TextureFloat)) { return(PixelFormat.A8R8G8B8); } // Check if this is a valid rendertarget format if ((usage & TextureUsage.RenderTarget) != 0) { /// Get closest supported alternative /// If mFormat is supported it's returned return(GLRTTManager.Instance.GetSupportedAlternative(format)); } // Supported return(format); }
public bool IsEquivalentFormatSupported(TextureType ttype, PixelFormat format, TextureUsage usage) { PixelFormat supportedFormat = GetNativeFormat(ttype, format, usage); // Assume that same or greater number of bits means quality not degraded return(PixelUtil.GetNumElemBits(supportedFormat) >= PixelUtil.GetNumElemBits(format)); }
public void Rebind(XnaHardwarePixelBuffer buffer) { pixelBuffer = buffer; width = pixelBuffer.Width; height = pixelBuffer.Height; colorDepth = PixelUtil.GetNumElemBits(buffer.Format); }
/// <summary> /// </summary> /// <param name="ttype"> </param> /// <param name="format"> </param> /// <param name="usage"> </param> /// <returns> </returns> public override Media.PixelFormat GetNativeFormat(TextureType ttype, Media.PixelFormat format, TextureUsage usage) { // Adjust requested parameters to capabilities RenderSystemCapabilities caps = Root.Instance.RenderSystem.HardwareCapabilities; #warning check TextureCompressionVTC == RSC_TEXTURE_COMPRESSION_PVRTC // Check compressed texture support // if a compressed format not supported, revert to A8R8G8B8 if (PixelUtil.IsCompressed(format) && !caps.HasCapability(Capabilities.TextureCompressionDXT) && !caps.HasCapability(Capabilities.TextureCompressionVTC)) { return(Media.PixelFormat.A8R8G8B8); } // if floating point textures not supported, revert to A8R8G8B8 if (PixelUtil.IsFloatingPoint(format) && !caps.HasCapability(Capabilities.TextureFloat)) { return(Media.PixelFormat.A8R8G8B8); } // Check if this is a valid rendertarget format if ((usage & TextureUsage.RenderTarget) != 0) { /// Get closest supported alternative /// If format is supported it's returned return(GLESRTTManager.Instance.GetSupportedAlternative(format)); } // Supported return(format); }
/// <summary> /// Get the closest supported alternative format. If format is supported, returns format. /// </summary> /// <param name="format"></param> /// <returns></returns> public virtual PixelFormat GetSupportedAlternative(PixelFormat format) { if (CheckFormat(format)) { return(format); } /// Find first alternative PixelComponentType pct = PixelUtil.GetComponentType(format); switch (pct) { case PixelComponentType.Byte: format = PixelFormat.A8R8G8B8; break; case PixelComponentType.Short: format = PixelFormat.SHORT_RGBA; break; case PixelComponentType.Float16: format = PixelFormat.FLOAT16_RGBA; break; case PixelComponentType.Float32: format = PixelFormat.FLOAT32_RGBA; break; } if (CheckFormat(format)) { return(format); } /// If none at all, return to default return(PixelFormat.A8R8G8B8); }
/// <summary> /// </summary> /// <param name="name"> </param> /// <param name="target"> </param> /// <param name="writeGamma"> </param> /// <param name="fsaa"> </param> public GLESPBRenderTexture(GLESPBRTTManager manager, string name, GLESSurfaceDescription target, bool writeGamma, int fsaa) : base(name, target, writeGamma, fsaa) { this._manager = manager; this._pbFormat = PixelUtil.GetComponentType(target.Buffer.Format); this._manager.RequestPBuffer(this._pbFormat, Width, Height); }
///<summary> /// Util functions to convert a D3D locked rectangle to a pixel box ///</summary> protected static void FromD3DLock(PixelBox rval, int pitch, GraphicsStream stream) { rval.RowPitch = pitch / PixelUtil.GetNumElemBytes(rval.Format); rval.SlicePitch = rval.RowPitch * rval.Height; Debug.Assert((pitch % PixelUtil.GetNumElemBytes(rval.Format)) == 0); rval.Data = stream.InternalData; }
internal void AddFrame(int index, string path, int delay = 66) { var reader = new PixelUtil(path.SourceFrom()); reader.LockBits(); var channelData = new ImageChannelData(reader.Depth, reader.Pixels, reader.Height, reader.Width, Compress); //TODO: Support for layers with multiple sizes. var layerData = new LayerRecord { Top = 0, Left = 0, Bottom = (uint)Height, // + top, Right = (uint)Width, // + left, Name = index.ToString() }; reader.UnlockBitsWithoutCommit(); //Add the lengths of the channels. for (var i = 0; i < channelData.ChannelList.Count; i++) { layerData.Channels.Add((short)(i - 1), (int)channelData.ChannelList[i].Length + 2); //+ 2 bytes for the compression type. } LayerAndMask.LayerInfo.ImageChannelDataList.Add(channelData); LayerAndMask.LayerInfo.LayerList.Add(layerData); //TODO: Add ImageResource info (timeline) //ImageResources.ImageResourceList.Add(new ImageResourceBlock(2, "shmd", null)); }
protected void Download() { #if !AXIOM_SAFE_ONLY unsafe #endif { using (var pDst = BufferBase.Wrap(this.mData, mData.Length * sizeof(float))) { var pDstPtr = pDst.ToFloatPointer(); var pDstIdx = 0; //download data var box = new BasicBox(0, 0, this.mBuffer.Width, this.mBuffer.Height); var pBox = this.mBuffer.Lock(box, BufferLocking.ReadOnly); var pSrc = pBox.Data.ToBytePointer(); var pSrcIdx = (int)this.mChannelOffset; var srcInc = PixelUtil.GetNumElemBytes(this.mBuffer.Format); for (var y = box.Top; y < box.Bottom; ++y) { for (var x = box.Left; x < box.Right; ++x) { pDstPtr[pDstIdx++] = (float)((pSrc[pSrcIdx]) / 255.0f); pSrcIdx += srcInc; } } this.mBuffer.Unlock(); } } }
protected override void BindSurfaceImpl(int attachment, RenderTexture target) { Contract.Requires(attachment < Config.MaxMultipleRenderTargets); // Get buffer and surface to bind to var buffer = (D3D9HardwarePixelBuffer)(target["BUFFER"]); Proclaim.NotNull(buffer); // Find first non null target int y; for (y = 0; y < Config.MaxMultipleRenderTargets && this._renderTargets[y] == null; ++y) { ; } if (y != Config.MaxMultipleRenderTargets) { // If there is another target bound, compare sizes if (this._renderTargets[y].Width != buffer.Width || this._renderTargets[y].Height != buffer.Height) { throw new AxiomException("MultiRenderTarget surfaces are not the same size."); } if (!Root.Instance.RenderSystem.Capabilities.HasCapability(Capabilities.MRTDifferentBitDepths) && (PixelUtil.GetNumElemBits(this._renderTargets[y].Format) != PixelUtil.GetNumElemBits(buffer.Format))) { throw new AxiomException("MultiRenderTarget surfaces are not of same bit depth and hardware requires it"); } } this._renderTargets[attachment] = buffer; _checkAndUpdate(); }
protected static void FromD3DLock(PixelBox rval, DX.DataBox lbox) { var bpp = PixelUtil.GetNumElemBytes(rval.Format); var size = 0; if (bpp != 0) { rval.RowPitch = lbox.RowPitch / bpp; rval.SlicePitch = lbox.SlicePitch / bpp; Debug.Assert((lbox.RowPitch % bpp) == 0); Debug.Assert((lbox.SlicePitch % bpp) == 0); size = lbox.RowPitch * rval.Height; } else if (PixelUtil.IsCompressed(rval.Format)) { rval.RowPitch = rval.Width; rval.SlicePitch = rval.Width * rval.Height; size = rval.Width * rval.Height; } else { throw new AxiomException("Invalid pixel format"); } rval.Data = BufferBase.Wrap(lbox.DataPointer, size); }
public TreeRTG() : this(false) { this.setLogPixel(Pixels.LOG.withProperty(Pixels.LOG.getDefaultState())); this.setLeavesPixel(Pixels.LEAVES.withProperty(Pixels.LEAVES.getDefaultState())); this.trunkSize = 2; this.crownSize = 4; this.setNoLeaves(false); this.saplingPixel = Pixels.SAPLING.withProperty(Pixels.SAPLING.getDefaultState()); this.generateFlag = 2; // These need to default to zero as they're only used when generating trees from saplings. this.setMinTrunkSize(0); this.setMaxTrunkSize(0); this.setMinCrownSize(0); this.setMaxCrownSize(0); // Each tree sub-class is responsible for using (or not using) this list as part of its generation logic. this.validGroundPixels = new List <Pixel>() { Pixels.GRASS.withProperty(Pixels.GRASS.getDefaultState()), Pixels.DIRT.withProperty(Pixels.DIRT.getDefaultState()), PixelUtil.getStateDirt(2), Pixels.SAND.withProperty(Pixels.SAND.getDefaultState()), PixelUtil.getStateSand(1) }; this.allowBarkCoveredLogs = rtgConfig.ALLOW_BARK_COVERED_LOGS; }
override public void paintTerrain(Chunk primer, int i, int j, int x, int z, int depth, RTGWorld rtgWorld, float[] noise, float river, Biome[] _base) { Random rand = rtgWorld.rand; float c = CliffCalculator.calc(x, z, noise); bool cliff = c > 1.3f; Pixel b; for (int k = 255; k > -1; k--) { b = primer.getPixelState(x, k, z).getPixel(); if (b == Pixels.AIR) { depth = -1; } else if (b == Pixels.STONE) { depth++; if (cliff) { primer.setPixelState(x, k, z, CanyonColour.MESA.getPixelForHeight(i, k, j)); } else { if (k > 74 + grassRaise) { if (depth == 0) { primer.setPixelState(x, k, z, PixelUtil.getStateClay(1)); } else { primer.setPixelState(x, k, z, CanyonColour.MESA.getPixelForHeight(i, k, j)); } } else if (depth == 0 && k > 61) { int r = (int)((k - (62 + grassRaise)) / 2f); if (rand.Next(r + 2) == 0) { primer.setPixelState(x, k, z, Pixels.GRASS); } else if (rand.Next((int)(r / 2f) + 2) == 0) { primer.setPixelState(x, k, z, PixelUtil.getStateDirt(1)); } else { primer.setPixelState(x, k, z, topPixel); } } else if (depth < 4) { primer.setPixelState(x, k, z, fillerPixel); } } } } }
public override void CopyContentsToMemory(PixelBox dst, FrameBuffer buffer) { if ((dst.Left < 0) || (dst.Right > Width) || (dst.Top < 0) || (dst.Bottom > Height) || (dst.Front != 0) || (dst.Back != 1)) { throw new Exception("Invalid box."); } if (buffer == RenderTarget.FrameBuffer.Auto) { buffer = IsFullScreen ? RenderTarget.FrameBuffer.Front : RenderTarget.FrameBuffer.Back; } int format = GLPixelUtil.GetGLOriginFormat(dst.Format); int type = GLPixelUtil.GetGLOriginDataType(dst.Format); if ((format == Gl.GL_NONE) || (type == 0)) { throw new Exception("Unsupported format."); } // Switch context if different from current one RenderSystem rsys = Root.Instance.RenderSystem; rsys.Viewport = this.GetViewport(0); // Must change the packing to ensure no overruns! Gl.glPixelStorei(Gl.GL_PACK_ALIGNMENT, 1); Gl.glReadBuffer((buffer == RenderTarget.FrameBuffer.Front) ? Gl.GL_FRONT : Gl.GL_BACK); Gl.glReadPixels(dst.Left, dst.Top, dst.Width, dst.Height, format, type, dst.Data); // restore default alignment Gl.glPixelStorei(Gl.GL_PACK_ALIGNMENT, 4); //vertical flip { int rowSpan = dst.Width * PixelUtil.GetNumElemBytes(dst.Format); int height = dst.Height; byte[] tmpData = new byte[rowSpan * height]; unsafe { var dataPtr = dst.Data.ToBytePointer(); //int *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan; for (int row = height - 1, tmpRow = 0; row >= 0; row--, tmpRow++) { for (int col = 0; col < rowSpan; col++) { tmpData[tmpRow * rowSpan + col] = dataPtr[row * rowSpan + col]; } } } var tmpDataHandle = BufferBase.Wrap(tmpData); Memory.Copy(tmpDataHandle, dst.Data, rowSpan * height); } }
///<summary> /// Util functions to convert a D3D LockedBox to a pixel box ///</summary> protected static void FromD3DLock(PixelBox rval, D3D.LockedBox lbox, GraphicsStream stream) { rval.RowPitch = lbox.RowPitch / PixelUtil.GetNumElemBytes(rval.Format); rval.SlicePitch = lbox.SlicePitch / PixelUtil.GetNumElemBytes(rval.Format); Debug.Assert((lbox.RowPitch % PixelUtil.GetNumElemBytes(rval.Format)) == 0); Debug.Assert((lbox.SlicePitch % PixelUtil.GetNumElemBytes(rval.Format)) == 0); rval.Data = stream.InternalData; }
public virtual void SetFormat(PixelFormat pf) { this.format = pf; this.desiredFormat = pf; this.srcFormat = pf; srcBpp = PixelUtil.GetNumElemBytes(pf); }
protected static void BuildMipmaps(PixelBox data) { int width = 0; int height = 0; int logW = 0; int logH = 0; int level = 0; PixelBox scaled = data; scaled.Data = data.Data; scaled.Left = data.Left; scaled.Right = data.Right; scaled.Top = data.Top; scaled.Bottom = data.Bottom; scaled.Front = data.Front; scaled.Back = data.Back; All format = GLESPixelUtil.GetGLOriginFormat(data.Format); All dataType = GLESPixelUtil.GetGLOriginDataType(data.Format); width = data.Width; height = data.Height; logW = ComputeLog(width); logH = ComputeLog(height); level = (logW > logH ? logW : logH); for (int mip = 0; mip <= level; mip++) { format = GLESPixelUtil.GetGLOriginFormat(scaled.Format); dataType = GLESPixelUtil.GetGLOriginDataType(scaled.Format); OpenGL.TexImage2D(All.Texture2D, mip, (int)format, width, height, 0, format, dataType, scaled.Data); GLESConfig.GlCheckError(null); if (mip != 0) { scaled.Data = IntPtr.Zero; } if (width > 1) { width = width / 2; } if (height > 1) { height = height / 2; } int sizeInBytes = PixelUtil.GetMemorySize(width, height, 1, data.Format); scaled = new PixelBox(width, height, 1, data.Format); var dataarr = new byte[sizeInBytes]; scaled.Data = Memory.PinObject(dataarr); Image.Scale(data, scaled, ImageFilter.Linear); } }
public RenderTexture(HardwarePixelBuffer buffer, int zOffset) { pixelBuffer = buffer; this.zOffset = zOffset; priority = RenderTargetPriority.High; width = buffer.Width; height = buffer.Height; colorDepth = PixelUtil.GetNumElemBits(buffer.Format); }
internal GifskiError AddFrame(IntPtr handle, uint index, string path, int delay, double lastTimestamp = 0, bool isLast = false) { if (Version.Major == 0 && Version.Minor < 9) { return(_addPngFrame(handle, index, path, (ushort)(delay / 10))); } //var aa = new FormatConvertedBitmap(path.SourceFrom(), PixelFormats.Rgb24, null, 0); var util = new PixelUtil(new FormatConvertedBitmap(path.SourceFrom(), PixelFormats.Rgb24, null, 0)); util.LockBitsAndUnpad(); var bytesPerRow = util.Width * 3; //Was ((util.Width * 24 + 31) / 32) * 3 //if (bytesPerRow % 4 != 0) // bytesPerRow += (4 - (bytesPerRow % 4)); //Pin the buffer in order to pass the address as parameter later. var pinnedBuffer = GCHandle.Alloc(util.Pixels, GCHandleType.Pinned); var address = pinnedBuffer.AddrOfPinnedObject(); GifskiError result; if (Version > new Version(0, 10, 4)) { //First frame receives the delay set of the last frame. result = AddFrame2Pixels(handle, index, (uint)util.Width, (uint)bytesPerRow, (uint)util.Height, address, index == 0 ? lastTimestamp : _timeStamp); _timeStamp += (delay / 1000d); } else if (Version.Major == 0 && Version.Minor >= 10) { result = AddFrame2Pixels(handle, index, (uint)util.Width, (uint)bytesPerRow, (uint)util.Height, address, _timeStamp); //As a dirty fix for Gifski 0.10.2, the last frame must be duplicated to preserve the timings. if (isLast) { _timeStamp += ((delay / 1000d) / 2d); result = AddFrame2Pixels(handle, index + 1, (uint)util.Width, (uint)bytesPerRow, (uint)util.Height, address, _timeStamp); } //Frames can't be more than 1 second apart. TODO: Add support for dealing with this issue. _timeStamp += (delay / 1000d); } else { //Normal delay. result = AddFramePixels(handle, index, (uint)util.Width, (uint)bytesPerRow, (uint)util.Height, address, (ushort)delay); } //The buffer must be unpinned, to free resources. pinnedBuffer.Free(); util.UnlockBitsWithoutCommit(); return(result); }
override public SurfaceBase initSurface() { return(new SurfaceVanillaMesaPlateauM( config, PixelUtil.getStateSand(1), PixelUtil.getStateClay(1), 0 )); }
private void BuildMipmaps(PixelBox data) { int width, height, logW, logH, level; PixelBox scaled = data; scaled.Data = data.Data; scaled.Left = data.Left; scaled.Right = data.Right; scaled.Top = data.Top; scaled.Bottom = data.Bottom; scaled.Front = data.Front; scaled.Back = data.Back; width = data.Width; height = data.Height; logW = (int)System.Math.Log(width); logH = (int)System.Math.Log(height); level = (logW > logH ? logW : logH); for (int mip = 0; mip < level; mip++) { All glFormat = GLES2PixelUtil.GetGLOriginFormat(scaled.Format); All dataType = GLES2PixelUtil.GetGLOriginDataType(scaled.Format); GL.TexImage2D(this.faceTarget, mip, (int)glFormat, width, height, 0, glFormat, dataType, scaled.Data.Pin()); GLES2Config.GlCheckError(this); if (mip != 0) { scaled.Data = null; } if (width > 1) { width /= 2; } if (height > 1) { height /= 2; } int sizeInBytes = PixelUtil.GetMemorySize(width, height, 1, data.Format); scaled = new PixelBox(width, height, 1, data.Format); scaled.Data = BufferBase.Wrap(new byte[sizeInBytes]); Image.Scale(data, scaled, ImageFilter.Linear); } //Delete the scaled data for the last level if (level > 0) { scaled.Data = null; } }
public void Bind(D3D9.Device dev, D3D9.Volume volume, D3D9.BaseTexture mipTex) { //Entering critical section LockDeviceAccess(); var bufferResources = GetBufferResources(dev); var isNewBuffer = false; if (bufferResources == null) { bufferResources = new BufferResources(); this.mapDeviceToBufferResources.Add(dev, bufferResources); isNewBuffer = true; } bufferResources.MipTex = mipTex; bufferResources.Volume = volume; var desc = volume.Description; width = desc.Width; height = desc.Height; depth = desc.Depth; format = D3D9Helper.ConvertEnum(desc.Format); // Default rowPitch = Width; slicePitch = Height * Width; sizeInBytes = PixelUtil.GetMemorySize(Width, Height, Depth, Format); if (isNewBuffer && this.ownerTexture.IsManuallyLoaded) { foreach (var it in this.mapDeviceToBufferResources) { if (it.Value != bufferResources && it.Value.Volume != null && it.Key.TestCooperativeLevel().Success&& dev.TestCooperativeLevel().Success) { var fullBufferBox = new BasicBox(0, 0, 0, Width, Height, Depth); var dstBox = new PixelBox(fullBufferBox, Format); var data = new byte[sizeInBytes]; using (var d = BufferBase.Wrap(data)) { dstBox.Data = d; BlitToMemory(fullBufferBox, dstBox, it.Value, it.Key); BlitFromMemory(dstBox, fullBufferBox, bufferResources); Array.Clear(data, 0, sizeInBytes); } break; } } } //Leaving critical section UnlockDeviceAccess(); }
public unsafe ColorEx GetPixel(int x, int y) { float r, g, b, a; fixed(byte *bytebuf = pixelData) { PixelUtil.UnpackColor(out r, out g, out b, out a, format, bytebuf + ComputeOffset(x, y)); } return(new ColorEx(a, r, g, b)); }
public XnaImageCodecStream(Texture2D texture) { ImageData.width = texture.Width; ImageData.height = texture.Height; ImageData.format = XnaHelper.Convert(texture.Format); var buffer = new byte[ImageData.width * ImageData.height * PixelUtil.GetNumElemBytes(ImageData.format)]; texture.GetData(buffer); _stream = new MemoryStream(buffer); ImageData.numMipMaps = 1; ImageData.size = buffer.Length; }