public void TileImage(Tile tile)
        {
            lock (tile)
            {
                if (tile.Thumbnail == null)
                {
                    return;
                }

                float xscaleFactor = (float)this.scaledWidth / MosaicWindow.MosaicInfo.TotalWidth;
                float yscaleFactor = (float)this.scaledHeight / MosaicWindow.MosaicInfo.TotalHeight;

                Size scaledSize = new Size((int)(tile.Width * xscaleFactor + 0.5),
                                           (int)(tile.Height * yscaleFactor + 0.5));

                Point scaledPosition = new Point();
                scaledPosition.X = (int)(tile.Position.X * xscaleFactor + 0.5);
                scaledPosition.Y = (int)(tile.Position.Y * yscaleFactor + 0.5);

                Rectangle dstRect = new Rectangle(scaledPosition, scaledSize);

                FreeImageAlgorithmsBitmap thumb = null;

                lock (tile.ThumbnailLock)
                {
                    thumb = new FreeImageAlgorithmsBitmap(tile.Thumbnail);
                }

                thumb.ConvertToStandardType(true);

                if (thumb.IsGreyScale)
                {
                    thumb.LinearScaleToStandardType(MosaicWindow.MosaicInfo.ThumbnailScaleMinIntensity,
                                                    MosaicWindow.MosaicInfo.ThumbnailScaleMaxIntensity);

                    thumb.SetGreyLevelPalette();
                }

                if (thumb.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
                {
                    MessageBox.Show("Failed to convert tile thumbnail to a standard type ?");
                }

                thumb.Rescale(dstRect.Size, FREE_IMAGE_FILTER.FILTER_BOX);

                thumb.ConvertTo24Bits();

                this.bitmap.PasteFromTopLeft(thumb, dstRect.Location, this.imageViewer.BlendingEnabled);

                thumb.Dispose();
            }

            this.Invalidate();
        }
Beispiel #2
0
        private void DrawThumbnailImage(Graphics graphics, Tile tile)
        {
            if (tile.Thumbnail != null)
            {
                lock (tile.ThumbnailLock)
                {
                    //tile.Thumbnail.ConvertToStandardType();
                    FreeImageAlgorithmsBitmap thumb = new FreeImageAlgorithmsBitmap(tile.Thumbnail);

                    if (thumb.IsGreyScale)
                    {
                        thumb.LinearScaleToStandardType(
                            mosaicInfo.ThumbnailScaleMinIntensity, mosaicInfo.ThumbnailScaleMaxIntensity);
                        thumb.SetGreyLevelPalette();
                    }

                    if (thumb.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
                    {
                        MessageBox.Show("Failed to convert tile thumbnail to a standard type ?");
                    }

                    graphics.DrawImage(thumb.ToBitmap(), tile.Bounds);

                    thumb.Dispose();
                }
            }

            /*
             * if (this.ShowFileNames)
             * {
             *  // Create font and brush.
             *  Font drawFont = new Font("Arial", 16);
             *  SolidBrush drawBrush = new SolidBrush(Color.Black);
             *
             *  Point location = new Point(tile.Bounds.Location.X + 100, tile.Bounds.Location.Y + 100);
             *
             *  SizeF size = graphics.MeasureString(tile.FileName, drawFont);
             *
             *  Brush brush = new SolidBrush(Color.FromArgb(50, Color.Gray));
             *
             *  graphics.FillRectangle(brush, location.X - 2, location.Y - 2,
             *      size.Width + 4, size.Height + 4);
             *
             *  graphics.DrawString(tile.FileName, drawFont, drawBrush,
             *      new PointF(location.X, location.Y));
             * }
             */

            if (this.ShowJoins)
            {
                Pen pen = new Pen(Color.Red, 2.0f);
                graphics.DrawRectangle(pen, tile.Bounds);
            }
        }
Beispiel #3
0
        public FreeImageAlgorithmsWPFImage(string filepath) : base()
        {
            this.FilePath = filepath;

            try
            {
                this.Fib = Tile.LoadFreeImageBitmapFromFile(filepath);
            }
            catch (Exception e)
            {
                throw;
            }

            ThumbnailFib = new FreeImageAlgorithmsBitmap(this.Fib);
            Tile.ResizeToThumbnail(ThumbnailFib);

            if (ThumbnailFib.IsGreyScale)
            {
                ThumbnailFib.LinearScaleToStandardType(0, 0);
            }
            else
            {
                ThumbnailFib.ConvertToStandardType(true);
            }

            Bitmap bitmap = ThumbnailFib.ToBitmap();

            System.Windows.Int32Rect rect = new System.Windows.Int32Rect();

            rect.X      = 0;
            rect.Y      = 0;
            rect.Width  = bitmap.Width;
            rect.Height = bitmap.Height;

            this.Source = ConvertGdiToWPF(bitmap, rect);
        }
Beispiel #4
0
        public FreeImageAlgorithmsBitmap LoadFreeImageBitmap(string filepath)
        {   // all overloaded functions come through this method
            FreeImageAlgorithmsBitmap fib = null;

            if (!System.IO.File.Exists(filepath))
            {
                this.dummyTile = true;
                return(new FreeImageAlgorithmsBitmap(this.Width, this.Height,
                                                     this.FreeImageType, this.colorDepth));
            }

            if (!(Tile.isCompositeRGB))
            {
                fib = LoadFreeImageBitmapFromFile(filepath);
            }
            else     //// Composite RGB: Insert 3 grey images into 1 24-bit colour image
            {
                FreeImageAlgorithmsBitmap fib8 = null;
                int n = Tile.nCompositeImages;

                // Crop images differently to apply the channel shift
                // shift for channel 0 will always be 0,0 but
                // crop for the channel with the min shift will be 0 to width-range and
                // crop for the channel with the max shift will be range to width.

                int   minX, minY, midX, midY, maxX, maxY, rX, rY;
                int[] orderX = new int[3], orderY = new int[3];
                int[] x      = new int[3], y = new int[3];
                x[0] = -Tile.channelShift[0].X;
                x[1] = -Tile.channelShift[1].X;
                x[2] = -Tile.channelShift[2].X;
                y[0] = -Tile.channelShift[0].Y;
                y[1] = -Tile.channelShift[1].Y;
                y[2] = -Tile.channelShift[2].Y;

                OrderShifts(x, orderX, out minX, out midX, out maxX);
                OrderShifts(y, orderY, out minY, out midY, out maxY);

                // ranges
                rX = maxX - minX;
                rY = maxY - minY;

                int[] shiftXl = new int[3], shiftYt = new int[3];
                int[] shiftXr = new int[3], shiftYb = new int[3];
                shiftXl[0] = 0;  // the shift for min shift channel
                shiftXr[0] = rX; // the shift for min shift channel
                shiftXl[1] = midX - minX;
                shiftXr[1] = maxX - midX;
                shiftXl[2] = rX; // the shift for max shift channel
                shiftXr[2] = 0;  // the shift for max shift channel
                shiftYt[0] = 0;  // the shift for min shift channel
                shiftYb[0] = rY; // the shift for min shift channel
                shiftYt[1] = midY - minY;
                shiftYb[1] = maxY - midY;
                shiftYt[2] = rY; // the shift for max shift channel
                shiftYb[2] = 0;  // the shift for max shift channel

                fib8 = LoadFreeImageBitmapFromFile(this.getFilePath(0));
                fib8.LinearScaleToStandardType(Tile.scaleMin[0], Tile.scaleMax[0]);
                //               fib8.Crop(0, 2, fib8.Width - 1 - 4, fib8.Height - 1);
                fib8.Crop(shiftXl[orderX[0]], shiftYt[orderY[0]], fib8.Width - 1 - shiftXr[orderX[0]], fib8.Height - 1 - shiftYb[orderY[0]]);
                fib = new FreeImageAlgorithmsBitmap(fib8.Width, fib8.Height, FREE_IMAGE_TYPE.FIT_BITMAP, 24);
                FreeImage.SetChannel(fib.Dib, fib8.Dib, Tile.channel[0]);
                fib8.Dispose();

                fib8 = LoadFreeImageBitmapFromFile(this.getFilePath(1));
                fib8.LinearScaleToStandardType(Tile.scaleMin[1], Tile.scaleMax[1]);
//                fib8.Crop(4, 0, fib8.Width - 1, fib8.Height - 1 - 2);
                fib8.Crop(shiftXl[orderX[1]], shiftYt[orderY[1]], fib8.Width - 1 - shiftXr[orderX[1]], fib8.Height - 1 - shiftYb[orderY[1]]);
                FreeImage.SetChannel(fib.Dib, fib8.Dib, Tile.channel[1]);
                fib8.Dispose();

                if (n == 3)  // may not have 3 files but should have at least 2
                {
                    fib8 = LoadFreeImageBitmapFromFile(this.getFilePath(2));
                    fib8.LinearScaleToStandardType(Tile.scaleMin[2], Tile.scaleMax[2]);
//                    fib8.Crop(2, 1, fib8.Width - 1 - 2, fib8.Height - 1 - 1);
                    fib8.Crop(shiftXl[orderX[2]], shiftYt[orderY[2]], fib8.Width - 1 - shiftXr[orderX[2]], fib8.Height - 1 - shiftYb[orderY[2]]);
                    FreeImage.SetChannel(fib.Dib, fib8.Dib, Tile.channel[2]);
                    fib8.Dispose();
                }
            }


            // Resample seems to only work for uint16 not int16 currently
            if (fib.ImageType == FREE_IMAGE_TYPE.FIT_INT16)
            {
                fib.ConvertInt16ToUInt16();
            }

            return(fib);
        }
Beispiel #5
0
        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();
            }
        }
Beispiel #6
0
        private void DrawIntermediateBitmap()
        {
            if (!this.intermediateBitmapDrawn)
            {
                this.threadController.ReportThreadStarted(this, "Started Zoom");

                float aspectRatio = (float)(this.mosaicInfo.TotalWidth) / this.mosaicInfo.TotalHeight;

                int scaledWidth  = Screen.PrimaryScreen.Bounds.Size.Width;
                int scaledHeight = (int)(scaledWidth / aspectRatio + 0.5);

                if (this.mosaicInfo.IsGreyScale)
                {
                    this.intermediateBitmap = new FreeImageAlgorithmsBitmap(scaledWidth, scaledHeight, 8);
                }
                else
                {
                    this.intermediateBitmap = new FreeImageAlgorithmsBitmap(scaledWidth, scaledHeight, 24);
                }

                float xscaleFactor = (float)scaledWidth / this.mosaicInfo.TotalWidth;
                float yscaleFactor = (float)scaledHeight / this.mosaicInfo.TotalHeight;

                if (this.intermediateBitmap == null)
                {
                    MessageBox.Show("Failed to create intermediate bitmap");
                }

                float scale = (float)scaledWidth / this.mosaicInfo.TotalWidth;

                Point scaledPosition = new Point();

                int count = 0;

                foreach (Tile tile in this.mosaicInfo.Items)
                {
                    if (tile.Thumbnail == null)
                    {
                        MessageBox.Show("Error thumnail is null");
                    }

                    //FreeImageAlgorithmsBitmap thumb = null;

                    //lock (tile.ThumbnailLock)
                    //{
                    //    thumb = new FreeImageAlgorithmsBitmap(tile.Thumbnail);
                    //}

                    FreeImageAlgorithmsBitmap fib = tile.LoadFreeImageBitmap();

                    fib.Rescale(new Size((int)(xscaleFactor * fib.Width), (int)(yscaleFactor * fib.Height)), FREE_IMAGE_FILTER.FILTER_BILINEAR);

                    if (fib.IsGreyScale)
                    {
                        fib.LinearScaleToStandardType(mosaicInfo.ScaleMinIntensity, mosaicInfo.ScaleMaxIntensity);

                        fib.SetGreyLevelPalette();
                    }
                    else
                    {
                        fib.ConvertToStandardType(true);
                    }

                    if (fib.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
                    {
                        MessageBox.Show("Failed to convert tile thumbnail to a standard type ?");
                    }

                    Size scaledSize = new Size((int)(tile.Width * xscaleFactor + 0.5),
                                               (int)(tile.Height * yscaleFactor + 0.5));

                    scaledPosition.X = (int)(tile.Position.X * xscaleFactor + 0.5);
                    scaledPosition.Y = (int)(tile.Position.Y * yscaleFactor + 0.5);

                    Rectangle dstRect = new Rectangle(scaledPosition, scaledSize);

                    intermediateBitmap.PasteFromTopLeft(fib, scaledPosition, this.BlendingEnabled);

                    fib.Dispose();

                    this.threadController.ReportThreadPercentage(this,
                                                                 "Performing Zoom", count++, this.tiles.Count);
                }
            }

            //intermediateBitmap.ConvertTo24Bits();

            this.intermediateBitmapDrawn = true;
            this.preventIdleProcessing   = false;
            this.dontDraw = false;

            this.threadController.ReportThreadCompleted(this, "Zoom Completed", false);

            this.Redraw();
            this.Invalidate();
        }