public ManagedBitmap ShrinkExpandWPF(ManagedBitmap source, double factor, Profile profile) { EnsureStarted(profile); ManagedBitmap result = new ManagedBitmap32(source.Width, source.Height); profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.ShrinkExpandWPF, new object[] { (int)Thread.CurrentThread.Priority, (int)source.Width, (int)source.Height, (string)source.BackingName, (string)result.BackingName, (double)factor, }); Profile serverProfile; ClientServerCommunication.WaitForDone(channel, out serverProfile); profile.Add(serverProfile); profile.Pop(); return(result); }
public ManagedBitmap CreateTile(ManagedBitmap source, int offsetX, int offsetY, int drawWidth, int drawHeight, int targetWidth, int targetHeight, Profile profile) { EnsureStarted(profile); ManagedBitmap result; string mapId; int width, height; Profile serverProfile; bool succeeded = false; profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.CreateTileGDI, new object[] { (int)Thread.CurrentThread.Priority, (string)source.BackingName, (int)source.Width, (int)source.Height, (int)offsetX, (int)offsetY, (int)drawWidth, (int)drawHeight, (int)targetWidth, (int)targetHeight }); try { ClientServerCommunication.WaitForPending(channel, out serverProfile, out mapId, out width, out height); profile.Add(serverProfile); result = new ManagedBitmap32(width, height, mapId); succeeded = true; } catch (ClientServerCommunication.RemoteException) { result = ManagedBitmap.CreateFromGDI(new Bitmap(Properties.Resources.InvalidPlaceHolder)); } profile.Pop(); if (succeeded) { profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.Clear, null); ClientServerCommunication.WaitForDone(channel, out serverProfile); profile.Add(serverProfile); profile.Pop(); } return(result); }
public ManagedBitmap LoadAndOrientGDI(string path, int rightRotations, Profile profile, out RotateFlipType exifOrientation) { EnsureStarted(profile); exifOrientation = RotateFlipType.RotateNoneFlipNone; ManagedBitmap result; string mapId; int width, height; Profile serverProfile; bool succeeded = false; profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.LoadAndOrientGDI, new object[] { (int)Thread.CurrentThread.Priority, (string)path, (int)rightRotations, }); try { object[] extra = ClientServerCommunication.WaitForPending(channel, out serverProfile, out mapId, out width, out height); exifOrientation = (RotateFlipType)(int)extra[0]; profile.Add(serverProfile); result = new ManagedBitmap32(width, height, mapId); succeeded = true; } catch (ClientServerCommunication.RemoteException) { result = ManagedBitmap.CreateFromGDI(new Bitmap(Properties.Resources.InvalidPlaceHolder)); } profile.Pop(); if (succeeded) { profile.Push("Remote call"); ClientServerCommunication.SendMessage( null /*log*/, channel, ClientServerCommunication.Commands.Clear, null); ClientServerCommunication.WaitForDone(channel, out serverProfile); profile.Add(serverProfile); profile.Pop(); } return(result); }
public override ManagedBitmap Clone() { if (disposed) { throw new InvalidOperationException(); } ManagedBitmap32 copy = new ManagedBitmap32(this.width, this.height); Debug.Assert(this.stride == copy.stride); Buffer.MemoryCopy(this.scan0, copy.scan0, TotalBytes, TotalBytes); return(copy); }
private static void ShrinkExpandGDI(Profile profile, int width, int height, string sourceMapName, string targetMapName, double factor) { profile.Push("ShrinkExpand [GDI]"); using (ManagedBitmap source = new ManagedBitmap32(width, height, sourceMapName)) { using (ManagedBitmap target = new ManagedBitmap32(width, height, targetMapName)) { Transforms.ShrinkExpand(profile, source, factor, target); } } profile.Pop(); }
private static void ResizeGDI(Profile profile, string sourceMapId, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, out ManagedBitmap targetBitmap) { profile.Push("Resize [GDI]"); using (ManagedBitmap source = new ManagedBitmap32(sourceWidth, sourceHeight, sourceMapId)) { profile.Push("Allocate"); targetBitmap = new ManagedBitmap32(targetWidth, targetHeight); profile.Pop(); Transforms.Resize(profile, source, targetBitmap); } profile.Pop(); }
private static void ShrinkExpandWPF(Profile profile, int width, int height, string sourceMapName, string targetMapName, double factor) { profile.Push("ShrinkExpand [WPF]"); using (SmartBitmap source = new SmartBitmap(new ManagedBitmap32(width, height, sourceMapName))) { profile.Push("Convert to WPF"); BitmapFrame wpfSource = source.AsWPF(); profile.Pop(); BitmapFrame wpfShrunkExpanded = Transforms.ShrinkExpand(profile, wpfSource, factor); profile.Push("Convert to Managed"); using (ManagedBitmap target = new ManagedBitmap32(wpfShrunkExpanded, targetMapName)) // copy into shared memory { } profile.Pop(); } profile.Pop(); }
// TODO: untested private unsafe static void CreateTileGDI(Profile profile, string sourceMapId, int sourceWidth, int sourceHeight, int offsetX, int offsetY, int drawWidth, int drawHeight, int targetWidth, int targetHeight, out ManagedBitmap targetBitmap) { profile.Push("CreateTileGDI"); using (ManagedBitmap sourceBitmap = new ManagedBitmap32(sourceWidth, sourceHeight, sourceMapId)) { using (Bitmap sourceBitmapGDI = new Bitmap(sourceWidth, sourceHeight, sourceBitmap.Stride, sourceBitmap.ImageFormat, new IntPtr(sourceBitmap.Scan0))) { targetBitmap = new ManagedBitmap32(targetWidth, targetHeight); using (Bitmap targetBitmapGDI = new Bitmap(targetWidth, targetHeight, targetBitmap.Stride, targetBitmap.ImageFormat, new IntPtr(targetBitmap.Scan0))) { using (Graphics graphics = Graphics.FromImage(targetBitmapGDI)) { graphics.FillRectangle(System.Drawing.Brushes.Black, 0, 0, targetWidth, targetHeight); graphics.DrawImage(sourceBitmapGDI, offsetX, offsetY, drawWidth, drawHeight); } } } } profile.Pop(); }
public unsafe override ManagedBitmap RotateFlip(RotateFlipType action) { ManagedBitmap32 copy; switch ((int)action) { default: Debug.Assert(false); throw new ArgumentException(); case 0: // RotateNoneFlipNone, Rotate180FlipXY case 4: // RotateNoneFlipX, Rotate180FlipY copy = (ManagedBitmap32)this.Clone(); break; case 1: // Rotate90FlipNone, Rotate270FlipXY case 5: // Rotate90FlipX, Rotate270FlipY copy = new ManagedBitmap32(this.Height, this.Width); for (int y = 0; y < this.Height; y++) { int *pThis = (int *)(this.scan0 + y * this.stride); int *pCopy = (int *)(copy.Scan0 + (this.Height - 1 - y) * 4); int copyStride = copy.stride / 4; for (int x = 0; x < this.Width; x++) { *pCopy = *pThis; pCopy += copyStride; pThis++; } } break; case 2: // Rotate180FlipNone, RotateNoneFlipXY case 6: // Rotate180FlipX, RotateNoneFlipY copy = new ManagedBitmap32(this.Width, this.Height); fixed(int *pBuf = &((new int[this.width])[0])) { for (int y = 0; y < this.Height; y++) { int *pThis = (int *)(this.scan0 + y * this.stride); int *pCopy = pBuf + this.width; for (int x = 0; x < this.Width; x++) { pCopy--; *pCopy = *pThis; pThis++; } Buffer.MemoryCopy(pBuf, copy.Scan0 + (this.height - 1 - y) * copy.stride, copy.stride, copy.stride); } } break; case 3: // Rotate270FlipNone, Rotate90FlipXY case 7: // Rotate270FlipX, Rotate90FlipY copy = new ManagedBitmap32(this.Height, this.Width); for (int y = 0; y < this.Height; y++) { int *pThis = (int *)(this.scan0 + y * this.stride); int *pCopy = (int *)(copy.Scan0 + y * 4 + this.width * copy.stride); int copyStride = copy.stride / 4; for (int x = 0; x < this.Width; x++) { pCopy -= copyStride; *pCopy = *pThis; pThis++; } } break; } // This could be optimized, but not for now since it is generally unused if ((int)action >= 4) { for (int y = 0; y < copy.Height; y++) { for (int x = 0; x < copy.Width / 2; x++) { int c = copy[x, y]; copy[x, y] = copy[copy.Width - 1 - x, y]; copy[copy.Width - 1 - x, y] = c; } } } return(copy); }