private void OnTileCorrelated(CorrelationTile tile, Rectangle bounds, FreeImageAlgorithmsBitmap fib, bool success) { this.tiledImageViewer.AddTile(bounds, fib); this.tiledImageViewer.Refresh(); #if DEBUG if (success == false) { FreeImageAlgorithmsBitmap bg = new FreeImageAlgorithmsBitmap(this.correlator.BackgroundImage); bg.ConvertTo24Bits(); bg.DrawColourRect(tile.OriginalBoundsRelativeToOrigin, Color.Red, 2); this.debugForm.BackgroundImageView.Image = bg.ToBitmap(); bg.Dispose(); } this.debugForm.Refresh(); #endif }
private void OnIdle(object sender, EventArgs e) { // Nothing todo. if (this.preventIdleProcessing == true) { return; } if (this.highResBitmapReady == true) { return; } if (this.imageSize.IsEmpty) { return; } if (this.highResBitmap == null) { return; } if (this.intermediateBitmapDrawn == true && this.NumberOfTilesExceedCacheThreshold) { return; } this.Cursor = Cursors.WaitCursor; Rectangle viewRect = ViewedImageSectionRect; this.idleTiles = Tile.GetTilesIntersectingRectangle(MosaicWindow.MosaicInfo.Items, viewRect); // Go through the tiles and draw them at the highest resolution. // This is where gradient blending should go also. if (this.highResBitmapReady == false && this.currentTileIdleProcess < this.idleTiles.Count) { Tile tile = this.idleTiles[this.currentTileIdleProcess]; FreeImageAlgorithmsBitmap fib = tile.LoadFreeImageBitmap(); if (fib.IsGreyScale) { fib.LinearScaleToStandardType(mosaicInfo.ScaleMinIntensity, mosaicInfo.ScaleMaxIntensity); fib.SetGreyLevelPalette(); } fib.ConvertTo24Bits(); if (this.zoom < 1.0) { fib.Rescale(new Size((int)(fib.Width * this.zoom), (int)(fib.Height * this.zoom)), FREE_IMAGE_FILTER.FILTER_BILINEAR); } Point pos = new Point(); // We may be using the thumbnails to display so // we need to work out the scaled coordinates if the zoom is < 1.0 // For 1.0 and above we draw in native res just the area we can see on the screen. if (this.zoom < 1.0f) { pos = tile.Position; pos.X = (int)(tile.Position.X - viewRect.Location.X + 0.5); pos.Y = (int)(tile.Position.Y - viewRect.Location.Y + 0.5); pos.X = (int)(this.zoom * pos.X); pos.Y = (int)(this.zoom * pos.Y); } else { pos.X = tile.Position.X - viewRect.Location.X; pos.Y = tile.Position.Y - viewRect.Location.Y; } lastIdleTileRectangles.Add(new Rectangle(pos, fib.Size)); if (highResBitmap.Bounds.IntersectsWith(new Rectangle(pos, fib.Size))) { highResBitmap.PasteFromTopLeft(fib, pos, this.blendingEnabled); } this.highResBitmapIsReset = false; fib.Dispose(); // We have completed the last tile if (this.currentTileIdleProcess == this.idleTiles.Count - 1) { // We are finished with the highres tiles // Draw the joins if neccessary if (this.ShowJoins) { int i = 0; foreach (Tile t in this.idleTiles) { highResBitmap.DrawColourRect(lastIdleTileRectangles[i++], Color.Red, 2); } } lastIdleTileSize.Width = (int)(Tile.GetHorizontalRangeOfTiles(idleTiles) * this.zoom); lastIdleTileSize.Height = (int)(Tile.GetVerticalRangeOfTiles(idleTiles) * this.zoom); this.Cursor = Cursors.Default; this.highResBitmapReady = true; } this.currentTileIdleProcess++; this.Invalidate(); } }