Exemplo n.º 1
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            IShapeContainer container = CurrentPage.SelectionContainer();

            if (container == null)
            {
                MessageBox.Show(Strings.Item("Container_Mismatch"));
                return;
            }

            transaction.Edit((Datum)container);
            Lined         mask  = FindSourceShape();
            ImportedImage image = FindSourceImage();

            transaction.Edit(mask);
            transaction.Edit(image);
            (mask as Pencil).ForceClosure(transaction);
            if (mask is Curve curve && !curve.Closed())
            {
                throw new UserException("[Mask_Not_Closed]");
            }
            MaskedImage result = new MaskedImage(image, mask);

            transaction.Create(result);

            int index = Math.Max(mask.Z, image.Z);             // this will be the Z-order of the new group

            result.Parent = container;
            container.Contents.Insert(index + 1, result);             // This index will be valid as the individual shapes are still in the list
            container.Contents.Remove(mask);
            container.Contents.Remove(image);
            container.FinishedModifyingContents(transaction, null);
            CurrentPage.SelectOnly(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports the IMG data saving it on RawOutputDirectory folder.
        /// </summary>
        public static void ExportIMGData()
        {
            List <string> paths = FileImportManager.ReadMultipleIMGFiles();

            for (int i = 0; i < paths.Count; i++)
            {
                List <ImportedImage> importedImageList = ExtractIMGData(paths[i]);
                string filePath = paths[i];
                string fileName = filePath.Split('\\').Last().Split('.').First();

                string pivotList    = "[\n";
                string pivotFileStr = $"{Parameters.PivotFileHeader}\n";
                Directory.CreateDirectory($@"{Parameters.RawOutputDirectory}\{fileName}");
                for (int j = 0; j < importedImageList.Count; j++)
                {
                    ImportedImage ii = importedImageList[j];

                    pivotFileStr += $"{j},{ii.Pivot.Item1},{ii.Pivot.Item2},{ii.RiderOffset.Item1},{ii.RiderOffset.Item2},{ii.RealRiderOffset.Item1},{ii.RealRiderOffset.Item2}\n";
                    pivotList    += $"[ {ii.RealRiderOffset.Item1}, {ii.RealRiderOffset.Item2} ],\n";
                    ii.BitmapImage.Save($@"{Parameters.RawOutputDirectory}\{fileName}\{fileName}_{j}.png");
                }

                pivotList += "]";

                Console.WriteLine($"Imported: {paths[i]}");
                File.WriteAllText($@"{Parameters.RawOutputDirectory}\{fileName}\{fileName}.txt", pivotFileStr);
                File.WriteAllText($@"{Parameters.RawOutputDirectory}\{fileName}\RiderPivot.txt", pivotList);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read a single image file
        /// </summary>
        /// <returns></returns>
        public static ImportedImage ReadSingleImage()
        {
            ImportedImage image = null;
            Thread        t     = new Thread(() =>
            {
                Console.WriteLine("Importing Images...");
                OpenFileDialog dialog   = new OpenFileDialog();
                dialog.Multiselect      = false;
                dialog.InitialDirectory = Parameters.OutputDirectory;
                dialog.Filter           = "Image Files (png)|*.png;";
                dialog.ShowDialog();

                foreach (string str in dialog.FileNames)
                {
                    image = new ImportedImage(str);
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();

            while (t.IsAlive)
            {
                Thread.Sleep(50);
            }

            return(image);
        }
        private bool TestColorFormatHeader(StreamReaderHelper stream, ImportedImage ii)
        {
            // The SOS header (start of scan).
            if (stream.GetWord(0, true) == 0xffda)
            {
                int components = stream.GetByte(4);
                if (components < 1 || components > 4 || components == 2)
                {
                    return(false);
                }
                // 1 for grayscale, 3 for RGB, 4 for CMYK.

                int blockLength = stream.GetWord(2, true);
                // Integrity check: correct size?
                if (blockLength != 6 + 2 * components)
                {
                    return(false);
                }

                // Eventually do more tests here.
                // Magic: we assume that all JPEG files with 4 components are RGBW (inverted CMYK) and not CMYK.
                // We add a test to tell CMYK from RGBW when we encounter a test file in CMYK format.
                ii.Information.ImageFormat = components == 3 ? ImageInformation.ImageFormats.JPEG :
                                             (components == 1 ? ImageInformation.ImageFormats.JPEGGRAY : ImageInformation.ImageFormats.JPEGRGBW);

                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        public static void makeBadge()
        {
            var img = ImportedImage.FromFile("badge-1.png", new ImageImportOptions()
            {
                HeightMapping = ImageImportOptions.HeightMappingMode.Vertical
            });

            img.Resize(Inches.One * 2.4, Inches.One * 2.75, Inches.Eigth).ToFile("badge");
        }
Exemplo n.º 6
0
 private void ImportPhotos(StorageFile sf)
 {
     if (sf.Path.ToLower().EndsWith(".jpg") || sf.Path.ToLower().EndsWith(".jpeg") || sf.Path.ToLower().EndsWith(".png") || sf.Path.ToLower().EndsWith(".bmp") || sf.Path.ToLower().EndsWith(".tiff"))
     {
         ImportedImage ii = new ImportedImage {
             Address = sf.Path, LinkedFile = sf
         };
         if (mainPageViewModel.ImageList.FirstOrDefault(s => s.Address == ii.Address) == null)
         {
             mainPageViewModel.ImageList.Add(ii);
             ii.Index = mainPageViewModel.ImageList.IndexOf(ii);
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Imports the image.
        /// </summary>
        public ImportedImage ImportImage(Stream stream, PdfDocument document)
        {
            StreamReaderHelper helper = new StreamReaderHelper(stream);

            // Try all registered importers to see if any of them can handle the image.
            foreach (IImageImporter importer in _importers)
            {
                helper.Reset();
                ImportedImage image = importer.ImportImage(helper, document);
                if (image != null)
                {
                    return(image);
                }
            }
            return(null);
        }
        private bool TestJfifHeader(StreamReaderHelper stream, ImportedImage ii)
        {
            // The App0 header should be the first header in every JFIF file.
            if (stream.GetWord(0, true) == 0xffe0)
            {
                // Now check for text "JFIF".
                if (stream.GetDWord(4, true) == 0x4a464946)
                {
                    int blockLength = stream.GetWord(2, true);
                    if (blockLength >= 16)
                    {
                        int version  = stream.GetWord(9, true);
                        int units    = stream.GetByte(11);
                        int densityX = stream.GetWord(12, true);
                        int densityY = stream.GetWord(14, true);

                        switch (units)
                        {
                        case 0:     // Aspect ratio only.
                            ii.Information.HorizontalAspectRatio = densityX;
                            ii.Information.VerticalAspectRatio   = densityY;
                            break;

                        case 1:     // DPI.
                            ii.Information.HorizontalDPI = densityX;
                            ii.Information.VerticalDPI   = densityY;
                            break;

                        case 2:     // DPCM.
                            ii.Information.HorizontalDPM = densityX * 100;
                            ii.Information.VerticalDPM   = densityY * 100;
                            break;
                        }

                        // More information here? More tests?
                        return(true);
                    }
                }
            }
            return(false);
        }
        private bool TestInfoHeader(StreamReaderHelper stream, ImportedImage ii)
        {
            // The SOF header (start of frame).
            int header = stream.GetWord(0, true);

            if (header >= 0xffc0 && header <= 0xffc3 ||
                header >= 0xffc9 && header <= 0xffcb)
            {
                // Lines in image.
                int sizeY = stream.GetWord(5, true);
                // Samples per line.
                int sizeX = stream.GetWord(7, true);

                // $THHO TODO: Check if we always get useful information here.
                ii.Information.Width  = (uint)sizeX;
                ii.Information.Height = (uint)sizeY;

                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
 private async void menuFlyoutShowInFileExplorer_Click(object sender, RoutedEventArgs e)
 {
     ImportedImage ii = (ImportedImage)(e.OriginalSource as FrameworkElement).DataContext;
     await Launcher.LaunchFileAsync(ii.LinkedFile);
 }
        private async void UserControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            if (DataContext != null && DataContext.GetType() == typeof(ImportedImage))
            {
                ImportedImage ii = (ImportedImage)DataContext;

                if (ii.Index % 2 == 0)
                {
                    rectangleDarken.Opacity = 0.1;
                }
                else
                {
                    rectangleDarken.Opacity = 0.05;
                }

                using (StorageItemThumbnail thumbnail2 = await ii.LinkedFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 1))
                {
                    if (thumbnail2 != null)
                    {
                        //Prepare thumbnail to display
                        var bitmapImage = new BitmapImage();
                        await bitmapImage.SetSourceAsync(thumbnail2);

                        imageThumbnail.Source = bitmapImage;
                        AnimationHelper.ChangeObjectOpacity(imageThumbnail, 0, 1, 75);
                    }
                }

                using (StorageItemThumbnail thumbnail = await ii.LinkedFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 250))
                {
                    if (thumbnail != null)
                    {
                        //Prepare thumbnail to display
                        var bitmapImage = new BitmapImage();
                        await bitmapImage.SetSourceAsync(thumbnail);

                        imageFull.Source    = bitmapImage;
                        imagePreview.Source = bitmapImage;
                        AnimationHelper.ChangeObjectOpacity(imageFull, 0, 1, 200);
                        AnimationHelper.ChangeObjectOpacity(imageThumbnail, 1, 0, 300, 200);
                    }
                }

                using (StorageItemThumbnail dominantColour = await ii.LinkedFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 1))
                {
                    if (dominantColour != null)
                    {
                        //Prepare thumbnail to display
                        var bitmapImage = new BitmapImage();
                        await bitmapImage.SetSourceAsync(dominantColour);

                        //Create a decoder for the image
                        var decoder = await BitmapDecoder.CreateAsync(dominantColour.CloneStream());

                        //Get the pixel provider
                        var pixels = await decoder.GetPixelDataAsync(
                            BitmapPixelFormat.Rgba8,
                            BitmapAlphaMode.Ignore,
                            new BitmapTransform(),
                            ExifOrientationMode.IgnoreExifOrientation,
                            ColorManagementMode.DoNotColorManage);

                        //Get the bytes of the 1x1 scaled image
                        var bytes = pixels.DetachPixelData();

                        //read the color
                        var myDominantColor = Color.FromArgb(255, bytes[0], bytes[1], bytes[2]);

                        gradientStop1.Color = Color.FromArgb(100, bytes[0], bytes[1], bytes[2]);
                        gradientStop2.Color = Color.FromArgb(255, bytes[0], bytes[1], bytes[2]);
                        ellipseRGB.Fill     = new SolidColorBrush(myDominantColor);
                    }
                }
            }
        }
Exemplo n.º 12
0
        private bool TestBitmapInfoHeader(StreamReaderHelper stream, ImportedImage ii, int offset)
        {
            int size = (int)stream.GetDWord(0, false);
            if (size == 40 || size == 108 || size == 124) // sizeof BITMAPINFOHEADER == 40, sizeof BITMAPV4HEADER == 108, sizeof BITMAPV5HEADER == 124
            {
                uint width = stream.GetDWord(4, false);
                int height = (int)stream.GetDWord(8, false);
                int planes = stream.GetWord(12, false);
                int bitcount = stream.GetWord(14, false);
                int compression = (int)stream.GetDWord(16, false);
                int sizeImage = (int)stream.GetDWord(20, false);
                int xPelsPerMeter = (int)stream.GetDWord(24, false);
                int yPelsPerMeter = (int)stream.GetDWord(28, false);
                uint colorsUsed = stream.GetDWord(32, false);
                uint colorsImportant = stream.GetDWord(36, false);
                // TODO Integrity and plausibility checks.
                if (sizeImage != 0 && sizeImage + offset > stream.Length)
                    return false;

                ImagePrivateDataBitmap privateData = (ImagePrivateDataBitmap)ii.Data;

                // Return true only for supported formats.
                if (compression == 0 || compression == 3) // BI_RGB == 0, BI_BITFIELDS == 3
                {
                    ((ImagePrivateDataBitmap)ii.Data).Offset = offset;
                    ((ImagePrivateDataBitmap)ii.Data).ColorPaletteOffset = stream.CurrentOffset + size;
                    ii.Information.Width = width;
                    ii.Information.Height = (uint)Math.Abs(height);
                    ii.Information.HorizontalDPM = xPelsPerMeter;
                    ii.Information.VerticalDPM = yPelsPerMeter;
                    privateData.FlippedImage = height < 0;
                    if (planes == 1 && bitcount == 24)
                    {
                        // RGB24
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.RGB24;

                        // TODO: Verify Mask if size >= 108 && compression == 3.
                        return true;
                    }
                    if (planes == 1 && bitcount == 32)
                    {
                        // ARGB32
                        //ii.Information.ImageFormat = ImageInformation.ImageFormats.ARGB32;
                        ii.Information.ImageFormat = compression == 0 ?
                            ImageInformation.ImageFormats.RGB24 :
                            ImageInformation.ImageFormats.ARGB32;

                        // TODO: tell RGB from ARGB. Idea: assume RGB if alpha is always 0.

                        // TODO: Verify Mask if size >= 108 && compression == 3.
                        return true;
                    }
                    if (planes == 1 && bitcount == 8)
                    {
                        // Palette8
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.Palette8;
                        ii.Information.ColorsUsed = colorsUsed;

                        return true;
                    }
                    if (planes == 1 && bitcount == 4)
                    {
                        // Palette8
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.Palette4;
                        ii.Information.ColorsUsed = colorsUsed;

                        return true;
                    }
                    if (planes == 1 && bitcount == 1)
                    {
                        // Palette8
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.Palette1;
                        ii.Information.ColorsUsed = colorsUsed;

                        return true;
                    }
                    // TODO Implement more formats!
                }
            }
            return false;
        }
Exemplo n.º 13
0
        private bool TestJfifHeader(StreamReaderHelper stream, ImportedImage ii)
        {
            // The App0 header should be the first header in every JFIF file.
            if (stream.GetWord(0, true) == 0xffe0)
            {
                // Now check for text "JFIF".
                if (stream.GetDWord(4, true) == 0x4a464946)
                {
                    int blockLength = stream.GetWord(2, true);
                    if (blockLength >= 16)
                    {
                        int version = stream.GetWord(9, true);
                        int units = stream.GetByte(11);
                        int densityX = stream.GetWord(12, true);
                        int densityY = stream.GetWord(14, true);

                        switch (units)
                        {
                            case 0: // Aspect ratio only.
                                ii.Information.HorizontalAspectRatio = densityX;
                                ii.Information.VerticalAspectRatio = densityY;
                                break;
                            case 1: // DPI.
                                ii.Information.HorizontalDPI = densityX;
                                ii.Information.VerticalDPI = densityY;
                                break;
                            case 2: // DPCM.
                                ii.Information.HorizontalDPM = densityX * 100;
                                ii.Information.VerticalDPM = densityY * 100;
                                break;
                        }

                        // More information here? More tests?
                        return true;
                    }
                }
            }
            return false;
        }
        private bool TestBitmapInfoHeader(StreamReaderHelper stream, ImportedImage ii, int offset)
        {
            int size = (int)stream.GetDWord(0, false);

            if (size == 40 || size == 108 || size == 124) // sizeof BITMAPINFOHEADER == 40, sizeof BITMAPV4HEADER == 108, sizeof BITMAPV5HEADER == 124
            {
                uint width           = stream.GetDWord(4, false);
                int  height          = (int)stream.GetDWord(8, false);
                int  planes          = stream.GetWord(12, false);
                int  bitcount        = stream.GetWord(14, false);
                int  compression     = (int)stream.GetDWord(16, false);
                int  sizeImage       = (int)stream.GetDWord(20, false);
                int  xPelsPerMeter   = (int)stream.GetDWord(24, false);
                int  yPelsPerMeter   = (int)stream.GetDWord(28, false);
                uint colorsUsed      = stream.GetDWord(32, false);
                uint colorsImportant = stream.GetDWord(36, false);
                // TODO Integrity and plausibility checks.
                if (sizeImage != 0 && sizeImage + offset > stream.Length)
                {
                    return(false);
                }

                ImagePrivateDataBitmap privateData = (ImagePrivateDataBitmap)ii.Data;

                // Return true only for supported formats.
                if (compression == 0 || compression == 3) // BI_RGB == 0, BI_BITFIELDS == 3
                {
                    ((ImagePrivateDataBitmap)ii.Data).Offset             = offset;
                    ((ImagePrivateDataBitmap)ii.Data).ColorPaletteOffset = stream.CurrentOffset + size;
                    ii.Information.Width         = width;
                    ii.Information.Height        = (uint)Math.Abs(height);
                    ii.Information.HorizontalDPM = xPelsPerMeter;
                    ii.Information.VerticalDPM   = yPelsPerMeter;
                    privateData.FlippedImage     = height < 0;
                    if (planes == 1 && bitcount == 24)
                    {
                        // RGB24
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.RGB24;

                        // TODO: Verify Mask if size >= 108 && compression == 3.
                        return(true);
                    }
                    if (planes == 1 && bitcount == 32)
                    {
                        // ARGB32
                        //ii.Information.ImageFormat = ImageInformation.ImageFormats.ARGB32;
                        ii.Information.ImageFormat = compression == 0 ?
                                                     ImageInformation.ImageFormats.RGB24 :
                                                     ImageInformation.ImageFormats.ARGB32;

                        // TODO: tell RGB from ARGB. Idea: assume RGB if alpha is always 0.

                        // TODO: Verify Mask if size >= 108 && compression == 3.
                        return(true);
                    }
                    if (planes == 1 && bitcount == 8)
                    {
                        // Palette8
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.Palette8;
                        ii.Information.ColorsUsed  = colorsUsed;

                        return(true);
                    }
                    if (planes == 1 && bitcount == 4)
                    {
                        // Palette8
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.Palette4;
                        ii.Information.ColorsUsed  = colorsUsed;

                        return(true);
                    }
                    if (planes == 1 && bitcount == 1)
                    {
                        // Palette8
                        ii.Information.ImageFormat = ImageInformation.ImageFormats.Palette1;
                        ii.Information.ColorsUsed  = colorsUsed;

                        return(true);
                    }
                    // TODO Implement more formats!
                }
            }
            return(false);
        }
Exemplo n.º 15
0
        private bool TestInfoHeader(StreamReaderHelper stream, ImportedImage ii)
        {
            // The SOF header (start of frame).
            int header = stream.GetWord(0, true);
            if (header >= 0xffc0 && header <= 0xffc3 ||
                header >= 0xffc9 && header <= 0xffcb)
            {
                // Lines in image.
                int sizeY = stream.GetWord(5, true);
                // Samples per line.
                int sizeX = stream.GetWord(7, true);

                // $THHO TODO: Check if we always get useful information here.
                ii.Information.Width = (uint)sizeX;
                ii.Information.Height = (uint)sizeY;

                return true;
            }
            return false;
        }
Exemplo n.º 16
0
        private bool TestColorFormatHeader(StreamReaderHelper stream, ImportedImage ii)
        {
            // The SOS header (start of scan).
            if (stream.GetWord(0, true) == 0xffda)
            {
                int components = stream.GetByte(4);
                if (components < 1 || components > 4 || components == 2)
                    return false;
                // 1 for grayscale, 3 for RGB, 4 for CMYK.

                int blockLength = stream.GetWord(2, true);
                // Integrity check: correct size?
                if (blockLength != 6 + 2 * components)
                    return false;

                // Eventually do more tests here.
                // Magic: we assume that all JPEG files with 4 components are RGBW (inverted CMYK) and not CMYK.
                // We add a test to tell CMYK from RGBW when we encounter a test file in CMYK format.
                ii.Information.ImageFormat = components == 3 ? ImageInformation.ImageFormats.JPEG :
                    (components == 1 ? ImageInformation.ImageFormats.JPEGGRAY : ImageInformation.ImageFormats.JPEGRGBW);

                return true;
            }
            return false;
        }
Exemplo n.º 17
0
        private void menuFlyoutRemoveImage_Click(object sender, RoutedEventArgs e)
        {
            ImportedImage ii = (ImportedImage)(e.OriginalSource as FrameworkElement).DataContext;

            mainPageViewModel.Delete(ii);
        }
Exemplo n.º 18
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            try
            {
                DataObject data = (DataObject)Clipboard.GetDataObject();
                if (data.GetDataPresent("Splash data", false))
                {
                    PasteSplashData(transaction, pnlView);
                }
#if SAW && !SPLASH
                else if (data.GetDataPresent("Splash scripts", false))
                {
                    CopyScripts.Paste(transaction);
                }
                else if (data.GetDataPresent("Splash presentation", false))
                {
                    CopyPresentation.Paste(transaction, pnlView);
                }
#endif
                else if (data.ContainsImage())
                {
                    Image        image      = data.GetImage();
                    MemoryStream strmMemory = new MemoryStream(10000);
                    image.Save(strmMemory, ImageFormat.Png);
                    image.Dispose();
                    ImportedImage objImported = new ImportedImage(strmMemory, CurrentDocument, transaction);                     //= ImportedImage.CreateForPaste(strmMemory)
                    transaction.Create(objImported);
                    objImported.PlaceAt(pnlView.ViewableArea().Centre());
                    //  strmMemory.Dispose()
                    CurrentPage.AddNew(objImported, transaction);
                }
                else if (ContainsFileImage(data))
                {
                    ImportedImage imported = new ImportedImage(data.GetFileDropList()[0], CurrentDocument, transaction);
                    transaction.Create(imported);
                    imported.PlaceAt(pnlView.ViewableArea().Centre());
                    CurrentPage.AddNew(imported, transaction);
                    CurrentPage.SelectOnly(imported);
                }
                else if (data.ContainsText())
                {
                    string text = data.GetText();
                    if (!string.IsNullOrEmpty(text))
                    {
                        // try and apply it to a shape - only if there is one and only one selected
                        Shape shape = pnlView.TypingShape();
                        if (shape != null && shape.SupportsTextLabel)                         // Second condition is needed because some "typing" shapes only actually do custom processing of certain keys
                        {
                            transaction.Edit(shape);
                            shape.TextType(text);
                        }
                        else if (CurrentPage.SelectedCount == 1)
                        {
                            shape = CurrentPage.SelectedShapes[0];
                            if (shape.SupportsTextLabel)
                            {
                                // When pasting in without the cursor, the entire current text is replaced, if any
                                transaction.Edit(shape);
                                if (!shape.HasText(true))
                                {
                                    shape.CreateLabel((Shape.TextStyleC)Editor.StyleParameterDefaultObject(Parameters.FontFace));
                                }
                                // StyleParameterDefaultObject returns the object for that param - which will be all the text styles
                                shape.LabelText = text.Replace("\r\n", "\r");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!Globals.Root.IsDebug)
            {
                Utilities.LogSubError(ex);
                transaction.Cancel();                 // must be before message box
                MessageBox.Show(Strings.Item("Paste_Failed"));
            }
        }
 public void Delete(ImportedImage image)
 {
     ImageList.Remove(image);
     Messenger.Default.Send("TryShowStartUI");
 }